【问题标题】:Why am I having a conflict between two StaticResource on the same control?为什么我在同一个控件上的两个 StaticResource 之间存在冲突?
【发布时间】:2013-10-10 03:43:34
【问题描述】:

我在控件的资源中声明了以下标记:

<conv:ActionItemToBooleanConverter x:Key="ActionItemToBooleanConverter" />

    <Style TargetType="{x:Type ListBox}">
        <Setter Property="ListBox.ItemTemplate">
            <Setter.Value>
                <DataTemplate>
                    <RadioButton  Content="Foo2"
                                  GroupName="FOo"
                                  IsChecked="{Binding CurrentProcessPoint, Converter={StaticResource ActionItemToBooleanConverter}, Mode=TwoWay}"
                                  Style="{StaticResource {x:Type ToggleButton}}" />
                </DataTemplate>
            </Setter.Value>
        </Setter>
    </Style>

对于 RadioButton,当我在 IsChecked 属性上引入 Converter={StaticResource ActionItemToBooleanConverter} 时,它突然给我的 Style="{StaticResource {x:Type ToggleButton}}" 带来了问题。样式下方出现蓝色波浪线,并显示“资源 {x:Type ToggleButton} 无法解析”。

为什么会这样?为我的 Converter 引入 StaticResource 导致我无法将 RadioButton 设置为 ToggleButton 的原因是什么?

我可以添加/修复什么来解决冲突?

谢谢

【问题讨论】:

  • 它在运行时工作吗?
  • 在 VS 2012 中,有时设计器会显示错误,而实际上并没有。有时这是一种皇家的痛苦。如果代码在您按 F5 时编译并运行,那就很好。
  • @Omribitan 它确实在运行时工作。因此,如果它是 VS2012 设计时问题,那就这样吧。我只是觉得它很奇怪,并想知道为什么会发生这些错误。感谢您的评论。
  • 如果关闭 XAML,错误是否仍然存在?

标签: c# wpf


【解决方案1】:

尝试重新构建项目,看看会发生什么。

【讨论】:

    猜你喜欢
    • 2012-04-14
    • 2020-04-16
    • 2017-10-30
    • 1970-01-01
    • 1970-01-01
    • 2012-11-24
    • 1970-01-01
    • 2011-03-10
    • 1970-01-01
    相关资源
    最近更新 更多