gpt4 book ai didi

.net - WPF 控件可以重复使用吗?

转载 作者:行者123 更新时间:2023-12-04 06:51:11 25 4
gpt4 key购买 nike

例如,我创建了一个带有复选标记的按钮。我需要在我窗口的几个地方使用它。

<Button Width="25">
<!-- Draw a Green checkmark -->
<Polyline Points="2,5,6,10,13,1" Stroke="Green" StrokeThickness="4" StrokeLineJoin="Round" StrokeStartLineCap="Round" StrokeEndLineCap="Round" />
</Button>

由于我只想更改内容,我不确定样式或模板是否适用。我需要创建一个用户控件吗?

编辑:这可以通过样式来完成。但是,我只想更改内容,不想覆盖当前样式。

最佳答案

这是一种风格的呼唤。将以下样式添加到您的 Window.Resources:

<style TargetType="Button" x:Key="tick">
<Setter Property="ContentTemplate">
<Setter.Value>
<DataTemplate>
<Polyline Points="2,5,6,10,13,1" Stroke="Green" StrokeThickness="4" StrokeLineJoin="Round" StrokeStartLineCap="Round" StrokeEndLineCap="Round" />
</DataTemplate>
</Setter.Value>
</Setter>
</Style>

然后您可以将按钮定义为:
<Button Width="25" Style="{StaticResource tick}" />

关于.net - WPF 控件可以重复使用吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3101817/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com