gpt4 book ai didi

c# - `...is not a DependencyProperty` 使用依赖属性和样式触发器时

转载 作者:行者123 更新时间:2023-12-03 18:47:07 27 4
gpt4 key购买 nike

在我的用户控件中:

public ODIF.DeviceChannel Channel
{
get { return (ODIF.DeviceChannel)GetValue(ChannelDP); }
set { SetValue(ChannelDP, value); }
}

public static readonly DependencyProperty ChannelDP = DependencyProperty.Register(
"ChannelProperty",
typeof(ODIF.DeviceChannel),
typeof(ChannelBox),
new PropertyMetadata(new ODIF.DeviceChannel()));
然后尝试在 XAML 中使用我的控件并绑定(bind)到 Channel使用数据触发器:
<local:ChannelBox VerticalAlignment="Top" HorizontalAlignment="Left" Width="200">
<local:ChannelBox.Resources>
<local:TypeOfConverter x:Key="TypeOfConverter"/>
</local:ChannelBox.Resources>
<local:ChannelBox.Style>
<Style TargetType="{x:Type local:ChannelBox}">
<Style.Triggers>
<DataTrigger Binding="{Binding mappingConnector, Converter={StaticResource TypeOfConverter}}" Value="{x:Type ODIF:MappingConnector}">
<Setter Property="Channel" Value="{Binding mappingConnector.plugin}" />
</DataTrigger>
<DataTrigger Binding="{Binding mappingConnector, Converter={StaticResource TypeOfConverter}}" Value="{x:Type ODIF:InitialMappingConnector}">
<Setter Property="Channel" Value="{Binding mappingConnector.SourceChannel}" />
</DataTrigger>
</Style.Triggers>
</Style>
</local:ChannelBox.Style>
</local:ChannelBox>
在 XAML 中引发以下错误:

The property "Channel" is not a DependencyProperty. To be used inmarkup, non-attached properties must be exposed on the target typewith an accessible instance property "Channel". For attachedproperties, the declaring type must provide static "GetChannel" and"SetChannel"methods.


但与错误让我相信的相反(我以某种方式错误地设置了 DP),以下似乎工作正常:
<local:ChannelBox VerticalAlignment="Top" HorizontalAlignment="Left" Width="200" Channel="{Binding mappingConnector.plugin}">
这意味着它似乎只有在 DataTrigger 中用作 Setter 属性时才会出现 DP 问题......

最佳答案

尝试命名您的静态属性 ChannelProperty而不是 ChannelDP .

关于c# - `...is not a DependencyProperty` 使用依赖属性和样式触发器时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35795670/

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