Reputation: 1073
My requirement is to apply multiple styles on a textbox having following situation:
when I do following it gives me error that I cannot apply DynamicResource to BasedOn:
<TextBox.Style>
<Style BasedOn="{DynamicResource MyTextStyle}" TargetType="{x:Type TextBox}">
<Setter Property="Text" Value="{Binding SelectedCall.Name}" />
<Style.Triggers>
<DataTrigger Binding="{Binding SelectedCall.Name}" Value="N/A">
<Setter Property="Text" Value="" />
</DataTrigger>
</Style.Triggers>
</Style>
</TextBox.Style>
please suggest me some solution so that I can apply this Dynamicresource as well as my datatrigger style
Upvotes: 2
Views: 7094
Reputation: 1319
Change DynamicResource
to StaticResource
like this:
<Style BasedOn="{StaticResource MyTextStyle}" TargetType="{x:Type TextBox}">
DynamicResource is intentionally not allowed in BasedOn.
EDIT: You got "Cannot find resource named 'EmptyTextBoxStyle'" because application can't find this particular static resource. To help application to find it you need to use MergedDictionary. Here is the example of how to use it inside e.g. Window:
<Window.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/Generic.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Window.Resources>
Inside another ResourceDictionary you should use this as the following:
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/Generic.xaml" />
</ResourceDictionary.MergedDictionaries>
You need to reference ResourceDictionary that contains definition for EmptyTextBoxStyle style in this way. So for example, if 'EmptyTextBoxStyle' is declared in Generic.xaml file and you're using it in ABC.xaml you can just use the above XAML (of course, you need to update Source attribute according to your project structure).
Upvotes: 8