Trying to override textbox for combobox styling (System.windows.markup.staticresourceholder exception)

和自甴很熟 提交于 2020-03-05 04:36:09

问题


I'm new in WPF and acccording to my previous question How to make selecteditem text red and bold on trigger (in combobox) I still have a problem with making my selecteditem (but not all combobox items) text red and bold in case when its IsNotCorrect property is true. If be more concrete I have system.windows.markup.staticresourceholder exception (it seems that all converters are declared, not sure of my new style declaring and the right order for it). These are the steps I have made:

  • create style to override textbox for my combobox at the beginning of my xaml file:

    <Style x:Key="UserDefinedStyle" TargetType="{x:Type ComboBox}">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type ComboBox}">
                        <TextBox x:Name="PART_EditableTextBox"          
               Template="{StaticResource ComboBoxTextBox}"
               HorizontalAlignment="Left"
               VerticalAlignment="Bottom"
               Margin="3,3,23,3"
               Focusable="True"
               Background="Transparent"
               Visibility="Hidden"/>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    
  • try to apply this style on my combobox (this part is inside of another style.

    <Border BorderBrush ="{Binding SelectedReason.IsNotCorrect, Converter={StaticResource DisablingBoolToColorConverter}}" BorderThickness="2">
    <ComboBox x:Name="REASON_ID" DisplayMemberPath="Name" IsReadOnly="True" IsEditable="True" SelectedItem="{Binding SelectedReason, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True}" Style"{DynamicResource UserDefinedStyle}">
         <ComboBox.ItemsSource>                                                          
              <CompositeCollection>
                  <ComboBoxItem Content="{DynamicResource lang_Common_SelectItem}" IsEnabled="False"/>
                  <CollectionContainer Collection="{Binding Source={StaticResource StaticReasons}}"/>
                  <TextBox x:Name="Part_EditableTextBox">
                     <TextBox.Style>
                        <Style TargetType="{x:Type TextBox}" BasedOn="{x:Null}">
                            <Style.Triggers>
                               <DataTrigger Binding="{Binding SelectedItem.IsNotCorrect, RelativeSource={RelativeSource AncestorType=ComboBox}}" Value="True">
                                    <Setter Property="Foreground" Value="Red" />
                                    <Setter Property="FontWeight" Value="Bold" />
                               </DataTrigger>
                            </Style.Triggers>
                         </Style>
                     <TextBox.Style>
                  </TextBox>
             </CompositeCollection>
        </ComboBox.ItemsSource>                                                    
    </ComboBox>                                                
    </Border>
    

来源:https://stackoverflow.com/questions/60295012/trying-to-override-textbox-for-combobox-styling-system-windows-markup-staticres

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!