Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
WPF如何将多个值获取到模板?_Wpf_Styles - Fatal编程技术网

WPF如何将多个值获取到模板?

WPF如何将多个值获取到模板?,wpf,styles,Wpf,Styles,第01行 line02 我想重新使用此模板。 模板需要两个可更改的值。 我只知道{TemplateBinding something} 如何展开值?您需要使用C#中的Dependency属性创建自定义控件 已经有一个类似的问题得到了回答。您可以用所需的结果详细解释哪些可变值等。您可以将Text=“{TemplatedBinding Name}”绑定为第一个文本块,将Text={TemplatedBinding Uid}绑定为第二个文本块,但更通用的方法是创建具有2个内容属性的自定义控件,并从b


第01行
line02
我想重新使用此模板。
模板需要两个可更改的值。
我只知道{TemplateBinding something}

如何展开值?

您需要使用C#中的Dependency属性创建自定义控件


已经有一个类似的问题得到了回答。

您可以用所需的结果详细解释哪些可变值等。您可以将
Text=“{TemplatedBinding Name}”
绑定为第一个文本块,将
Text={TemplatedBinding Uid}
绑定为第二个文本块,但更通用的方法是创建具有2个内容属性的自定义控件,并从button派生,而不是使用button
<Style x:Key="TestButton" TargetType="{x:Type Button}">
<Setter Property="Foreground" Value="White"/>
<Setter Property="Template">
    <Setter.Value>
        <ControlTemplate TargetType="{x:Type Button}">
            <Grid>
                <Border Background="{TemplateBinding Background}" CornerRadius="5" BorderThickness="10" BorderBrush="{TemplateBinding BorderBrush}"/>

                    <StackPanel VerticalAlignment="Center">
                        <TextBlock HorizontalAlignment="Center" FontSize="50">line01</TextBlock>
                        <TextBlock HorizontalAlignment="Center" FontSize="80">line02</TextBlock>
                    </StackPanel>
                    <ContentPresenter/>
                </Grid>
                <ControlTemplate.Triggers>
                    <Trigger Property="IsMouseOver" Value="True">
                        <Setter Property="Foreground" Value="Black"/>
                    </Trigger>
                </ControlTemplate.Triggers>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>
DependencyProperty.Register("My_Property_Name_1", typeof(String), typeof(Custom_Control));
DependencyProperty.Register("My_Property_Name_2", typeof(String), typeof(Custom_Control));