I created a style in XAML, How Can I return this style in style selector (code)?
I created style in XAML and I want to only return the style which is declared in XAML.
You can add a property to your StyleSelector
and then use the property to pass a reference to the Style
in XAML.
public class MyStyleSelector : StyleSelector
{
private Style styleToUse;
public Style StyleToUse
{
get { return styleToUse; }
set { styleToUse = value; }
}
public override Style SelectStyle(object item, DependencyObject container)
{
return styleToUse;
}
}
<Control StyleSelector="{DynamicResource myStyleSelector}">
<Control.Resources>
<Style x:Key="myStyle">
...
</Style>
<local:MyStyleSelector x:Key="myStyleSelector" StyleToUse="{StaticResource myStyle}"/>
</Control.Resources>
</Control>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With