我想从使用自定义控件的用户控件传递参数,并在我的自定义控件的cs上使用它。例如,如果我在UserControl上有自定义控件
在UserControl中(例如ThisViewName.XAML):
<ctrl:PinWindowControl Tag="ThisViewName" Grid.Row="0"/>
其中只包含一个按钮
Generic.xaml:
<Style TargetType="{x:Type local:PinWindowControl}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type local:PinWindowControl}">
<Border Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}">
<Button Width="100" Height="100"></Button>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
如何将标签一直提供给我的PinWindowControl.cs文件?
答案 0 :(得分:1)
假设您在DependencyProperty
中创建了PinWindowControl
:
您可以使用Tag
访问this.Tag
。您的PinWindowControl
与partial class
相关联XAML
。
public class PinWindowControl.cs : FrameworkElement
{
public PinWindowControl()
{
Debug.WriteLine(this.Tag);
}
}