How to bind property of the VM with the key “ResourceKey” using the DynamicResource extension?

I have the resources of icons for buttons, icons, presented in the form of a XAML Resource. I need to link a property IconBrush from the model submitting with a key expansion DynamicResource.
<Button
Grid.Row="2"
Grid.Column="1"
Width="48"
BorderBrush="{x:Null}"
 Command="{Binding OpenDialogIcons}"
 CommandParameter="{Binding RelativeSource={RelativeSource Mode=Self}}"
 Style="{StaticResource BubleButton}">
<Button.Content>
 <!-- This bind is not working how can I solve the problem? -->
 <DynamicResource ResourceKey="{Binding IconBrush.ResourceKey, Mode=TwoWay}"/>
</Button.Content>
 </Button>

Property from the view model:
public DynamicResourceExtension IconBrush
{
 get { return _iconBrush; }
set
{
 SetProperty(ref _iconBrush, value, () => IconBrush);
}
}

Initialize the property:
Resources IconResources = IconResources new();
IconBrush = resources.DrawIcon();

In this method get resource management icons. This code is also flawed I am looking for a better solution because you have to use an iterator.
public DynamicResourceExtension DrawIcon()
{
 ResourceDictionary resource = new ResourceDictionary();
 resource.Source = new Uri("../../Resources/Icons.xaml", UriKind.Relative);
 DynamicResourceExtension dynamicResource = new DynamicResourceExtension();

 foreach (var key in resource.Keys)
{
 if ((string) key == "SettingIcon")
 dynamicResource.ResourceKey = key;
}
 return dynamicResource;
}
March 23rd 20 at 18:44
0 answer

Find more questions by tags XAMLC#WPF