C# 如何从codebehind使用DynamicSource?
我经常在XAML中编写以下代码:C# 如何从codebehind使用DynamicSource?,c#,wpf,resources,C#,Wpf,Resources,我经常在XAML中编写以下代码: (...) xmlns:vs="clr-namespace:Microsoft.VisualStudio.Shell;assembly=Microsoft.VisualStudio.Shell.12.0" (...) <Path Fill="{DynamicResource {x:Static vs:VsBrushes.GrayText}}"> (…) xmlns:vs=“clr命名空间:Microsoft.VisualStudio.Shell;
(...)
xmlns:vs="clr-namespace:Microsoft.VisualStudio.Shell;assembly=Microsoft.VisualStudio.Shell.12.0"
(...)
<Path Fill="{DynamicResource {x:Static vs:VsBrushes.GrayText}}">
(…)
xmlns:vs=“clr命名空间:Microsoft.VisualStudio.Shell;assembly=Microsoft.VisualStudio.Shell.12.0”
(...)
如何从codebehind创建这样的路径
?(确切地说:如何将DynamicSource附加到dependency属性?我希望这有助于:
编辑:在您的情况下,它应该如下所示:
pathObject.SetResourceReference(Path.FillProperty, Microsoft.VisualStudio.Shell.VsBrushes.GrayText);
我不知道为什么文档中说第二个参数应该是Object name,它实际上接受了resource
键
但是,我不太确定如何使用vs:vsbrush.GrayText笔刷
。这很简单:)PathName.SetResourceReference(Path.FillProperty,vsbrush.GrayText)
(在之后使用Microsoft.VisualStudio.Shell
)
PathName.SetResourceReference(Path.FillProperty, "NameOfBrush");