<Window x:Class="WPFComboBoxEditable.WindowXShared"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="WindowXShared" Height="356" Width="547">
<Window.Resources>
<Rectangle x:Shared="false" x:Key="rect" Width="20" Height="20" Fill="Green" />
</Window.Resources>
<StackPanel>
<Border Child="{StaticResource rect}" />
<Button Content="{StaticResource rect}" />
<Button Content="{StaticResource rect}" />
</StackPanel>
</Window>
Limitation:
It must be remembered that we can only set x:Shared in XAML. It can not be set through code.
Visual Studio 2008 seems issues with usage of resources using x:Shared. That is why even if we disallow sharing [using x:Shared = false], it still can not load the designer.
It also shows it as error when we try to Load the Designer. Don't worry, it builds and run fine.
XAML also highlights this as error. If we hover over the highlighted text, it shows the error message. Remember this is just designer issue that it does not support that. As discussed above, the build should be fine.
Note:
The default value of x:Shared is true (x:Shared = true) that is why the resources are shared among all the components using them.
No comments:
Post a Comment