积极答复者
触发器,如何设置控件中的对象类型的依赖属性的对象子属性值变化作为条件?

问题
答案
-
根据 Requirements for a Custom Class as a XAML Element 在 XAML 中无法执行要执行的操作:
自定义类不得是嵌套类。嵌套类及其常规 CLR 用法语法中的“点”会干扰其他 WPF 和/或 XAML 功能,例如附加属性。
MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.- 已标记为答案 Trian555 2022年11月10日 10:44
全部回复
-
Hi,@Trian555 。你可以给我分享你的可以重现问题的完整的示例代码来重现问题和分析吗?
MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com. -
Hi,@Trian555 。你可以给我分享你的可以重现问题的完整的示例代码来重现问题和分析吗?
MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.你好,假如我自定义一个控件,其中有一个IList集合类型的依赖属性
public class TestCustomControl : Control { static TestCustomControl() { DefaultStyleKeyProperty.OverrideMetadata(typeof(TestCustomControl), new FrameworkPropertyMetadata(typeof(TestCustomControl))); } public IList TestList { get { return (IList )GetValue(TestListProperty); } set { SetValue(TestListProperty, value); } } // Using a DependencyProperty as the backing store for TestList. This enables animation, styling, binding, etc... public static readonly DependencyProperty TestListProperty = DependencyProperty.Register("TestList", typeof(IList ), typeof(TestCustomControl), new PropertyMetadata(null)); }
xaml:
<Style TargetType="{x:Type local:TestCustomControl}"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type local:TestCustomControl}"> <Border Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}"> </Border> <ControlTemplate.Triggers> <Trigger Property="local:TestCustomControl.TestList.Count" Value="0"> <Setter Property="Background" Value="Green" ></Setter> <Setter Property="BorderBrush" Value="Blue" ></Setter> <Setter Property="BorderThickness" Value="2" ></Setter> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> </Setter> </Style>
//<Trigger Property="local:TestCustomControl.TestList.Count" Value="1">提示不支持的嵌套类型
-
根据 Requirements for a Custom Class as a XAML Element 在 XAML 中无法执行要执行的操作:
自定义类不得是嵌套类。嵌套类及其常规 CLR 用法语法中的“点”会干扰其他 WPF 和/或 XAML 功能,例如附加属性。
MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.- 已标记为答案 Trian555 2022年11月10日 10:44