我无法弄清楚如何引用XAML文件中XAML文件定义的当前实例对象.
我有一个转换器,我想在当前实例中作为参数对象发送.
{Binding Path=<bindingObject>, Converter={x:Static namespace:Converter.Instance}, ConverterParameter=this}
Run Code Online (Sandbox Code Playgroud)
在此代码中,它将转换为字符串,而不是对当前实例对象的引用.
谢谢
约翰
我有一个图像,我需要在我的应用程序中使用几个地方.我想在资源字典中只定义一次图像,并让我的其他xaml文件就是那个定义.我能做的一件事我无法弄清楚的是如何引用定义为xaml元素的东西而不是xaml属性中的属性.
这是我的ResourceDictionary
# resourceDictionary.xaml
<LinearGradientBrush x:Key="MyGradient" StartPoint="0,0.5" EndPoint="1,0.5">
<GradientStop Color="#A5000000" Offset="0"/>
<GradientStop Color="#00000000" Offset="1"/>
</LinearGradientBrush>
<Image x:Key="MyImage" Source="MyGlyph.png" Width="20" Height="20" />
Run Code Online (Sandbox Code Playgroud)
所以在我的xaml中我知道如何引用渐变作为控件对象的属性
<TextBlock Text="Sample Text" Background="{DynamicResource MessageGradient}"/>
Run Code Online (Sandbox Code Playgroud)
但我想弄清楚他如何引用Image是一个完整的控制对象.此示例仅创建一个按钮,该按钮在按钮中具有文本"{DynamicResource MyImage}"而不是图像.
<!-- Want MyImage to be content of the button -->
<Button>
{DynamicResource MyImage}
</Button>
Run Code Online (Sandbox Code Playgroud)
有没有一种简单的方法可以做到这一点,或者我必须创建一个仅包含我的图像的控件模板,然后在我的xaml中有一个使用控件模板的图像标签?