Reputation: 303
A problem appears (x:Key attribute required) when I add: <s:RsuSensorVisible x:Key="RsuSensorLocalVisible"/>
in my code. The code is posted below and also a picture attached. It seems that they cancel each other. If I remove<s:RsuSensorVisible x:Key="RsuSensorLocalVisible"/>
works perfect. Some solution?
public class RsuSensorVisible : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
//string stringValue = ((ContentControl)value).Content;
var stringValue = value as string;
if (!string.IsNullOrEmpty(stringValue))
{
return stringValue == "RSU" ? Visibility.Visible : Visibility.Hidden;
}
return Visibility.Visible;
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
}
<Window.Resources>
<s:RsuSensorVisible x:Key="RsuSensorLocalVisible"/>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Resources/DesignerItem.xaml" />
<ResourceDictionary Source="Resources/ToolboxItem.xaml" />
<ResourceDictionary Source="Resources/Toolbox.xaml" />
<ResourceDictionary Source="Resources/Connection.xaml" />
<ResourceDictionary Source="Resources/Stencils/FlowChartStencils.xaml" />
<ResourceDictionary Source="Resources/Stencils/ShapeStencils.xaml" />
<ResourceDictionary Source="Resources/Stencils/SymbolStencils.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Window.Resources>
Upvotes: 0
Views: 176
Reputation: 355
I can't comment, so i'll post an answer.
Have you tried putting your <s:RsuSensorVisible x:Key="RsuSensorLocalVisible"/>
inside ResourceDictionary? Or maybe, try to give x:Key
attribute to your ResourceDictionary. It looks like that's the problem
Upvotes: 1
Reputation: 911
Just put the RsuSensorVisible variable inside the ResourceDictionary declaration and the problem will go away. The content of the Window.Resources element must be a ResourceDictionary.
<Window.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Resources/DesignerItem.xaml" />
<ResourceDictionary Source="Resources/ToolboxItem.xaml" />
<ResourceDictionary Source="Resources/Toolbox.xaml" />
<ResourceDictionary Source="Resources/Connection.xaml" />
<ResourceDictionary Source="Resources/Stencils/FlowChartStencils.xaml" />
<ResourceDictionary Source="Resources/Stencils/ShapeStencils.xaml" />
<ResourceDictionary Source="Resources/Stencils/SymbolStencils.xaml" />
</ResourceDictionary.MergedDictionaries>
<s:RsuSensorVisible x:Key="RsuSensorLocalVisible"/>
</ResourceDictionary>
</Window.Resources>
Upvotes: 1