Combobox Template Text statt Pfeil

  • WPF
  • .NET (FX) 4.5–4.8

Es gibt 3 Antworten in diesem Thema. Der letzte Beitrag () ist von Nofear23m.

    Combobox Template Text statt Pfeil

    Hallo Leute!

    Ich hätte gerne eine Combobox, in der statt des Pfeils ein Text steht. Dazu habe ich erst einmal eine Kopie der Combobox-Vorlage geändert. Es funktioniert auch soweit wie gewünscht. Jetzt müsste der Buchstabe / Text aber per Binding vorzugeben sein, statt fest vorgegeben. Wie löst man so etwas? Hier der aktuelle Stand.

    Quellcode

    1. <UserControl.Resources>
    2. <Style x:Key="FocusVisual">
    3. <Setter Property="Control.Template">
    4. <Setter.Value>
    5. <ControlTemplate>
    6. <Rectangle Margin="2" SnapsToDevicePixels="true" Stroke="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}" StrokeThickness="1" StrokeDashArray="1 2"/>
    7. </ControlTemplate>
    8. </Setter.Value>
    9. </Setter>
    10. </Style>
    11. <LinearGradientBrush x:Key="ComboBox.Static.Background" EndPoint="0,1" StartPoint="0,0">
    12. <GradientStop Color="#FFF0F0F0" Offset="0.0"/>
    13. <GradientStop Color="#FFE5E5E5" Offset="1.0"/>
    14. </LinearGradientBrush>
    15. <SolidColorBrush x:Key="ComboBox.Static.Border" Color="#FFACACAC"/>
    16. <SolidColorBrush x:Key="ComboBox.Static.Editable.Background" Color="#FFFFFFFF"/>
    17. <SolidColorBrush x:Key="ComboBox.Static.Editable.Border" Color="#FFABADB3"/>
    18. <SolidColorBrush x:Key="ComboBox.Static.Editable.Button.Background" Color="Transparent"/>
    19. <SolidColorBrush x:Key="ComboBox.Static.Editable.Button.Border" Color="Transparent"/>
    20. <SolidColorBrush x:Key="ComboBox.MouseOver.Glyph" Color="#FF000000"/>
    21. <LinearGradientBrush x:Key="ComboBox.MouseOver.Background" EndPoint="0,1" StartPoint="0,0">
    22. <GradientStop Color="#FFECF4FC" Offset="0.0"/>
    23. <GradientStop Color="#FFDCECFC" Offset="1.0"/>
    24. </LinearGradientBrush>
    25. <SolidColorBrush x:Key="ComboBox.MouseOver.Border" Color="#FF7EB4EA"/>
    26. <SolidColorBrush x:Key="ComboBox.MouseOver.Editable.Background" Color="#FFFFFFFF"/>
    27. <SolidColorBrush x:Key="ComboBox.MouseOver.Editable.Border" Color="#FF7EB4EA"/>
    28. <LinearGradientBrush x:Key="ComboBox.MouseOver.Editable.Button.Background" EndPoint="0,1" StartPoint="0,0">
    29. <GradientStop Color="#FFEBF4FC" Offset="0.0"/>
    30. <GradientStop Color="#FFDCECFC" Offset="1.0"/>
    31. </LinearGradientBrush>
    32. <SolidColorBrush x:Key="ComboBox.MouseOver.Editable.Button.Border" Color="#FF7EB4EA"/>
    33. <SolidColorBrush x:Key="ComboBox.Pressed.Glyph" Color="#FF000000"/>
    34. <LinearGradientBrush x:Key="ComboBox.Pressed.Background" EndPoint="0,1" StartPoint="0,0">
    35. <GradientStop Color="#FFDAECFC" Offset="0.0"/>
    36. <GradientStop Color="#FFC4E0FC" Offset="1.0"/>
    37. </LinearGradientBrush>
    38. <SolidColorBrush x:Key="ComboBox.Pressed.Border" Color="#FF569DE5"/>
    39. <SolidColorBrush x:Key="ComboBox.Pressed.Editable.Background" Color="#FFFFFFFF"/>
    40. <SolidColorBrush x:Key="ComboBox.Pressed.Editable.Border" Color="#FF569DE5"/>
    41. <LinearGradientBrush x:Key="ComboBox.Pressed.Editable.Button.Background" EndPoint="0,1" StartPoint="0,0">
    42. <GradientStop Color="#FFDAEBFC" Offset="0.0"/>
    43. <GradientStop Color="#FFC4E0FC" Offset="1.0"/>
    44. </LinearGradientBrush>
    45. <SolidColorBrush x:Key="ComboBox.Pressed.Editable.Button.Border" Color="#FF569DE5"/>
    46. <SolidColorBrush x:Key="ComboBox.Disabled.Glyph" Color="#FFBFBFBF"/>
    47. <SolidColorBrush x:Key="ComboBox.Disabled.Background" Color="#FFF0F0F0"/>
    48. <SolidColorBrush x:Key="ComboBox.Disabled.Border" Color="#FFD9D9D9"/>
    49. <SolidColorBrush x:Key="ComboBox.Disabled.Editable.Background" Color="#FFFFFFFF"/>
    50. <SolidColorBrush x:Key="ComboBox.Disabled.Editable.Border" Color="#FFBFBFBF"/>
    51. <SolidColorBrush x:Key="ComboBox.Disabled.Editable.Button.Background" Color="Transparent"/>
    52. <SolidColorBrush x:Key="ComboBox.Disabled.Editable.Button.Border" Color="Transparent"/>
    53. <SolidColorBrush x:Key="ComboBox.Static.Glyph" Color="#FF606060"/>
    54. <Style x:Key="ComboBoxToggleButton" TargetType="{x:Type ToggleButton}">
    55. <Setter Property="OverridesDefaultStyle" Value="true"/>
    56. <Setter Property="IsTabStop" Value="false"/>
    57. <Setter Property="Focusable" Value="false"/>
    58. <Setter Property="ClickMode" Value="Press"/>
    59. <Setter Property="Template">
    60. <Setter.Value>
    61. <ControlTemplate TargetType="{x:Type ToggleButton}">
    62. <Border x:Name="templateRoot" BorderBrush="{StaticResource ComboBox.Static.Border}" BorderThickness="{TemplateBinding BorderThickness}" Background="{StaticResource ComboBox.Static.Background}" SnapsToDevicePixels="true">
    63. <Border x:Name="splitBorder" BorderBrush="Transparent" BorderThickness="1" HorizontalAlignment="Right" Margin="0" SnapsToDevicePixels="true" Width="{DynamicResource {x:Static SystemParameters.VerticalScrollBarWidthKey}}">
    64. <!--<Path x:Name="arrow" Data="F1 M 0,0 L 2.667,2.66665 L 5.3334,0 L 5.3334,-1.78168 L 2.6667,0.88501 L0,-1.78168 L0,0 Z" Fill="{StaticResource ComboBox.Static.Glyph}" HorizontalAlignment="Center" Margin="0" VerticalAlignment="Center"/>-->
    65. <TextBlock Text="B" Margin="2,2,2,2" HorizontalAlignment="Center" VerticalAlignment="Center"/>
    66. </Border>
    67. </Border>
    68. <ControlTemplate.Triggers>
    69. <MultiDataTrigger>
    70. <MultiDataTrigger.Conditions>
    71. <Condition Binding="{Binding IsEditable, RelativeSource={RelativeSource AncestorType={x:Type ComboBox}}}" Value="true"/>
    72. <Condition Binding="{Binding IsMouseOver, RelativeSource={RelativeSource Self}}" Value="false"/>
    73. <Condition Binding="{Binding IsPressed, RelativeSource={RelativeSource Self}}" Value="false"/>
    74. <Condition Binding="{Binding IsEnabled, RelativeSource={RelativeSource Self}}" Value="true"/>
    75. </MultiDataTrigger.Conditions>
    76. <Setter Property="Background" TargetName="templateRoot" Value="{StaticResource ComboBox.Static.Editable.Background}"/>
    77. <Setter Property="BorderBrush" TargetName="templateRoot" Value="{StaticResource ComboBox.Static.Editable.Border}"/>
    78. <Setter Property="Background" TargetName="splitBorder" Value="{StaticResource ComboBox.Static.Editable.Button.Background}"/>
    79. <Setter Property="BorderBrush" TargetName="splitBorder" Value="{StaticResource ComboBox.Static.Editable.Button.Border}"/>
    80. </MultiDataTrigger>
    81. <Trigger Property="IsMouseOver" Value="true">
    82. <!--<Setter Property="Fill" TargetName="arrow" Value="{StaticResource ComboBox.MouseOver.Glyph}"/>-->
    83. </Trigger>
    84. <MultiDataTrigger>
    85. <MultiDataTrigger.Conditions>
    86. <Condition Binding="{Binding IsMouseOver, RelativeSource={RelativeSource Self}}" Value="true"/>
    87. <Condition Binding="{Binding IsEditable, RelativeSource={RelativeSource AncestorType={x:Type ComboBox}}}" Value="false"/>
    88. </MultiDataTrigger.Conditions>
    89. <Setter Property="Background" TargetName="templateRoot" Value="{StaticResource ComboBox.MouseOver.Background}"/>
    90. <Setter Property="BorderBrush" TargetName="templateRoot" Value="{StaticResource ComboBox.MouseOver.Border}"/>
    91. </MultiDataTrigger>
    92. <MultiDataTrigger>
    93. <MultiDataTrigger.Conditions>
    94. <Condition Binding="{Binding IsMouseOver, RelativeSource={RelativeSource Self}}" Value="true"/>
    95. <Condition Binding="{Binding IsEditable, RelativeSource={RelativeSource AncestorType={x:Type ComboBox}}}" Value="true"/>
    96. </MultiDataTrigger.Conditions>
    97. <Setter Property="Background" TargetName="templateRoot" Value="{StaticResource ComboBox.MouseOver.Editable.Background}"/>
    98. <Setter Property="BorderBrush" TargetName="templateRoot" Value="{StaticResource ComboBox.MouseOver.Editable.Border}"/>
    99. <Setter Property="Background" TargetName="splitBorder" Value="{StaticResource ComboBox.MouseOver.Editable.Button.Background}"/>
    100. <Setter Property="BorderBrush" TargetName="splitBorder" Value="{StaticResource ComboBox.MouseOver.Editable.Button.Border}"/>
    101. </MultiDataTrigger>
    102. <Trigger Property="IsPressed" Value="true">
    103. <!--<Setter Property="Fill" TargetName="arrow" Value="{StaticResource ComboBox.Pressed.Glyph}"/>-->
    104. </Trigger>
    105. <MultiDataTrigger>
    106. <MultiDataTrigger.Conditions>
    107. <Condition Binding="{Binding IsPressed, RelativeSource={RelativeSource Self}}" Value="true"/>
    108. <Condition Binding="{Binding IsEditable, RelativeSource={RelativeSource AncestorType={x:Type ComboBox}}}" Value="false"/>
    109. </MultiDataTrigger.Conditions>
    110. <Setter Property="Background" TargetName="templateRoot" Value="{StaticResource ComboBox.Pressed.Background}"/>
    111. <Setter Property="BorderBrush" TargetName="templateRoot" Value="{StaticResource ComboBox.Pressed.Border}"/>
    112. </MultiDataTrigger>
    113. <MultiDataTrigger>
    114. <MultiDataTrigger.Conditions>
    115. <Condition Binding="{Binding IsPressed, RelativeSource={RelativeSource Self}}" Value="true"/>
    116. <Condition Binding="{Binding IsEditable, RelativeSource={RelativeSource AncestorType={x:Type ComboBox}}}" Value="true"/>
    117. </MultiDataTrigger.Conditions>
    118. <Setter Property="Background" TargetName="templateRoot" Value="{StaticResource ComboBox.Pressed.Editable.Background}"/>
    119. <Setter Property="BorderBrush" TargetName="templateRoot" Value="{StaticResource ComboBox.Pressed.Editable.Border}"/>
    120. <Setter Property="Background" TargetName="splitBorder" Value="{StaticResource ComboBox.Pressed.Editable.Button.Background}"/>
    121. <Setter Property="BorderBrush" TargetName="splitBorder" Value="{StaticResource ComboBox.Pressed.Editable.Button.Border}"/>
    122. </MultiDataTrigger>
    123. <Trigger Property="IsEnabled" Value="false">
    124. <!--<Setter Property="Fill" TargetName="arrow" Value="{StaticResource ComboBox.Disabled.Glyph}"/>-->
    125. </Trigger>
    126. <MultiDataTrigger>
    127. <MultiDataTrigger.Conditions>
    128. <Condition Binding="{Binding IsEnabled, RelativeSource={RelativeSource Self}}" Value="false"/>
    129. <Condition Binding="{Binding IsEditable, RelativeSource={RelativeSource AncestorType={x:Type ComboBox}}}" Value="false"/>
    130. </MultiDataTrigger.Conditions>
    131. <Setter Property="Background" TargetName="templateRoot" Value="{StaticResource ComboBox.Disabled.Background}"/>
    132. <Setter Property="BorderBrush" TargetName="templateRoot" Value="{StaticResource ComboBox.Disabled.Border}"/>
    133. </MultiDataTrigger>
    134. <MultiDataTrigger>
    135. <MultiDataTrigger.Conditions>
    136. <Condition Binding="{Binding IsEnabled, RelativeSource={RelativeSource Self}}" Value="false"/>
    137. <Condition Binding="{Binding IsEditable, RelativeSource={RelativeSource AncestorType={x:Type ComboBox}}}" Value="true"/>
    138. </MultiDataTrigger.Conditions>
    139. <Setter Property="Background" TargetName="templateRoot" Value="{StaticResource ComboBox.Disabled.Editable.Background}"/>
    140. <Setter Property="BorderBrush" TargetName="templateRoot" Value="{StaticResource ComboBox.Disabled.Editable.Border}"/>
    141. <Setter Property="Background" TargetName="splitBorder" Value="{StaticResource ComboBox.Disabled.Editable.Button.Background}"/>
    142. <Setter Property="BorderBrush" TargetName="splitBorder" Value="{StaticResource ComboBox.Disabled.Editable.Button.Border}"/>
    143. </MultiDataTrigger>
    144. </ControlTemplate.Triggers>
    145. </ControlTemplate>
    146. </Setter.Value>
    147. </Setter>
    148. </Style>
    149. <ControlTemplate x:Key="ComboBoxTemplate" TargetType="{x:Type ComboBox}">
    150. <Grid x:Name="templateRoot" SnapsToDevicePixels="true">
    151. <Grid.ColumnDefinitions>
    152. <ColumnDefinition Width="*"/>
    153. <ColumnDefinition MinWidth="{DynamicResource {x:Static SystemParameters.VerticalScrollBarWidthKey}}" Width="0"/>
    154. </Grid.ColumnDefinitions>
    155. <Popup x:Name="PART_Popup" AllowsTransparency="true" Grid.ColumnSpan="2" IsOpen="{Binding IsDropDownOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}" Margin="1" PopupAnimation="{DynamicResource {x:Static SystemParameters.ComboBoxPopupAnimationKey}}" Placement="Bottom">
    156. <Themes:SystemDropShadowChrome x:Name="shadow" Color="Transparent" MaxHeight="{TemplateBinding MaxDropDownHeight}" MinWidth="{Binding ActualWidth, ElementName=templateRoot}">
    157. <Border x:Name="dropDownBorder" BorderBrush="{DynamicResource {x:Static SystemColors.WindowFrameBrushKey}}" BorderThickness="1" Background="{DynamicResource {x:Static SystemColors.WindowBrushKey}}">
    158. <ScrollViewer x:Name="DropDownScrollViewer">
    159. <Grid x:Name="grid" RenderOptions.ClearTypeHint="Enabled">
    160. <Canvas x:Name="canvas" HorizontalAlignment="Left" Height="0" VerticalAlignment="Top" Width="0">
    161. <Rectangle x:Name="opaqueRect" Fill="{Binding Background, ElementName=dropDownBorder}" Height="{Binding ActualHeight, ElementName=dropDownBorder}" Width="{Binding ActualWidth, ElementName=dropDownBorder}"/>
    162. </Canvas>
    163. <ItemsPresenter x:Name="ItemsPresenter" KeyboardNavigation.DirectionalNavigation="Contained" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
    164. </Grid>
    165. </ScrollViewer>
    166. </Border>
    167. </Themes:SystemDropShadowChrome>
    168. </Popup>
    169. <ToggleButton x:Name="toggleButton" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" Grid.ColumnSpan="2" IsChecked="{Binding IsDropDownOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}" Style="{StaticResource ComboBoxToggleButton}"/>
    170. <ContentPresenter x:Name="contentPresenter" ContentTemplate="{TemplateBinding SelectionBoxItemTemplate}" ContentTemplateSelector="{TemplateBinding ItemTemplateSelector}" Content="{TemplateBinding SelectionBoxItem}" ContentStringFormat="{TemplateBinding SelectionBoxItemStringFormat}" TextBlock.Foreground="Red" HorizontalAlignment="Center" IsHitTestVisible="false" Margin="2" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="Center"/>
    171. <!--<ContentPresenter x:Name="contentPresenter" ContentTemplate="{TemplateBinding SelectionBoxItemTemplate}" ContentTemplateSelector="{TemplateBinding ItemTemplateSelector}" Content="{TemplateBinding SelectionBoxItem}" ContentStringFormat="{TemplateBinding SelectionBoxItemStringFormat}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" IsHitTestVisible="false" Margin="{TemplateBinding Padding}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>-->
    172. </Grid>
    173. <ControlTemplate.Triggers>
    174. <Trigger Property="HasDropShadow" SourceName="PART_Popup" Value="true">
    175. <Setter Property="Margin" TargetName="shadow" Value="0,0,5,5"/>
    176. <Setter Property="Color" TargetName="shadow" Value="#71000000"/>
    177. </Trigger>
    178. <Trigger Property="HasItems" Value="false">
    179. <Setter Property="Height" TargetName="dropDownBorder" Value="95"/>
    180. </Trigger>
    181. <MultiTrigger>
    182. <MultiTrigger.Conditions>
    183. <Condition Property="IsGrouping" Value="true"/>
    184. <Condition Property="VirtualizingPanel.IsVirtualizingWhenGrouping" Value="false"/>
    185. </MultiTrigger.Conditions>
    186. <Setter Property="ScrollViewer.CanContentScroll" Value="false"/>
    187. </MultiTrigger>
    188. <Trigger Property="ScrollViewer.CanContentScroll" SourceName="DropDownScrollViewer" Value="false">
    189. <Setter Property="Canvas.Top" TargetName="opaqueRect" Value="{Binding VerticalOffset, ElementName=DropDownScrollViewer}"/>
    190. <Setter Property="Canvas.Left" TargetName="opaqueRect" Value="{Binding HorizontalOffset, ElementName=DropDownScrollViewer}"/>
    191. </Trigger>
    192. </ControlTemplate.Triggers>
    193. </ControlTemplate>
    194. <SolidColorBrush x:Key="TextBox.Static.Background" Color="#FFFFFFFF"/>
    195. <Style x:Key="ComboBoxEditableTextBox" TargetType="{x:Type TextBox}">
    196. <Setter Property="OverridesDefaultStyle" Value="true"/>
    197. <Setter Property="AllowDrop" Value="true"/>
    198. <Setter Property="MinWidth" Value="0"/>
    199. <Setter Property="MinHeight" Value="0"/>
    200. <Setter Property="FocusVisualStyle" Value="{x:Null}"/>
    201. <Setter Property="ScrollViewer.PanningMode" Value="VerticalFirst"/>
    202. <Setter Property="Stylus.IsFlicksEnabled" Value="False"/>
    203. <Setter Property="Template">
    204. <Setter.Value>
    205. <ControlTemplate TargetType="{x:Type TextBox}">
    206. <ScrollViewer x:Name="PART_ContentHost" Background="Transparent" Focusable="false" HorizontalScrollBarVisibility="Hidden" VerticalScrollBarVisibility="Hidden"/>
    207. </ControlTemplate>
    208. </Setter.Value>
    209. </Setter>
    210. </Style>
    211. <ControlTemplate x:Key="ComboBoxEditableTemplate" TargetType="{x:Type ComboBox}">
    212. <Grid x:Name="templateRoot" SnapsToDevicePixels="true">
    213. <Grid.ColumnDefinitions>
    214. <ColumnDefinition Width="*"/>
    215. <ColumnDefinition MinWidth="{DynamicResource {x:Static SystemParameters.VerticalScrollBarWidthKey}}" Width="0"/>
    216. </Grid.ColumnDefinitions>
    217. <Popup x:Name="PART_Popup" AllowsTransparency="true" Grid.ColumnSpan="2" IsOpen="{Binding IsDropDownOpen, RelativeSource={RelativeSource TemplatedParent}}" PopupAnimation="{DynamicResource {x:Static SystemParameters.ComboBoxPopupAnimationKey}}" Placement="Bottom">
    218. <Themes:SystemDropShadowChrome x:Name="shadow" Color="Transparent" MaxHeight="{TemplateBinding MaxDropDownHeight}" MinWidth="{Binding ActualWidth, ElementName=templateRoot}">
    219. <Border x:Name="dropDownBorder" BorderBrush="{DynamicResource {x:Static SystemColors.WindowFrameBrushKey}}" BorderThickness="1" Background="{DynamicResource {x:Static SystemColors.WindowBrushKey}}">
    220. <ScrollViewer x:Name="DropDownScrollViewer">
    221. <Grid x:Name="grid" RenderOptions.ClearTypeHint="Enabled">
    222. <Canvas x:Name="canvas" HorizontalAlignment="Left" Height="0" VerticalAlignment="Top" Width="0">
    223. <Rectangle x:Name="opaqueRect" Fill="{Binding Background, ElementName=dropDownBorder}" Height="{Binding ActualHeight, ElementName=dropDownBorder}" Width="{Binding ActualWidth, ElementName=dropDownBorder}"/>
    224. </Canvas>
    225. <ItemsPresenter x:Name="ItemsPresenter" KeyboardNavigation.DirectionalNavigation="Contained" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
    226. </Grid>
    227. </ScrollViewer>
    228. </Border>
    229. </Themes:SystemDropShadowChrome>
    230. </Popup>
    231. <ToggleButton x:Name="toggleButton" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" Grid.ColumnSpan="2" IsChecked="{Binding IsDropDownOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}" Style="{StaticResource ComboBoxToggleButton}"/>
    232. <Border x:Name="border" Background="{StaticResource TextBox.Static.Background}" Margin="{TemplateBinding BorderThickness}">
    233. <TextBox x:Name="PART_EditableTextBox" HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}" IsReadOnly="{Binding IsReadOnly, RelativeSource={RelativeSource TemplatedParent}}" Margin="{TemplateBinding Padding}" Style="{StaticResource ComboBoxEditableTextBox}" VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"/>
    234. </Border>
    235. </Grid>
    236. <ControlTemplate.Triggers>
    237. <Trigger Property="IsEnabled" Value="false">
    238. <Setter Property="Opacity" TargetName="border" Value="0.56"/>
    239. </Trigger>
    240. <Trigger Property="IsKeyboardFocusWithin" Value="true">
    241. <Setter Property="Foreground" Value="Black"/>
    242. </Trigger>
    243. <Trigger Property="HasDropShadow" SourceName="PART_Popup" Value="true">
    244. <Setter Property="Margin" TargetName="shadow" Value="0,0,5,5"/>
    245. <Setter Property="Color" TargetName="shadow" Value="#71000000"/>
    246. </Trigger>
    247. <Trigger Property="HasItems" Value="false">
    248. <Setter Property="Height" TargetName="dropDownBorder" Value="95"/>
    249. </Trigger>
    250. <MultiTrigger>
    251. <MultiTrigger.Conditions>
    252. <Condition Property="IsGrouping" Value="true"/>
    253. <Condition Property="VirtualizingPanel.IsVirtualizingWhenGrouping" Value="false"/>
    254. </MultiTrigger.Conditions>
    255. <Setter Property="ScrollViewer.CanContentScroll" Value="false"/>
    256. </MultiTrigger>
    257. <Trigger Property="ScrollViewer.CanContentScroll" SourceName="DropDownScrollViewer" Value="false">
    258. <Setter Property="Canvas.Top" TargetName="opaqueRect" Value="{Binding VerticalOffset, ElementName=DropDownScrollViewer}"/>
    259. <Setter Property="Canvas.Left" TargetName="opaqueRect" Value="{Binding HorizontalOffset, ElementName=DropDownScrollViewer}"/>
    260. </Trigger>
    261. </ControlTemplate.Triggers>
    262. </ControlTemplate>
    263. <Style x:Key="ComboBoxStyle1" TargetType="{x:Type ComboBox}">
    264. <Setter Property="FocusVisualStyle" Value="{StaticResource FocusVisual}"/>
    265. <Setter Property="Background" Value="{StaticResource ComboBox.Static.Background}"/>
    266. <Setter Property="BorderBrush" Value="{StaticResource ComboBox.Static.Border}"/>
    267. <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.WindowTextBrushKey}}"/>
    268. <Setter Property="BorderThickness" Value="1"/>
    269. <Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Auto"/>
    270. <Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto"/>
    271. <Setter Property="Padding" Value="6,3,5,3"/>
    272. <Setter Property="ScrollViewer.CanContentScroll" Value="true"/>
    273. <Setter Property="ScrollViewer.PanningMode" Value="Both"/>
    274. <Setter Property="Stylus.IsFlicksEnabled" Value="False"/>
    275. <Setter Property="Template" Value="{StaticResource ComboBoxTemplate}"/>
    276. <Style.Triggers>
    277. <Trigger Property="IsEditable" Value="true">
    278. <Setter Property="IsTabStop" Value="false"/>
    279. <Setter Property="Padding" Value="2"/>
    280. <Setter Property="Template" Value="{StaticResource ComboBoxEditableTemplate}"/>
    281. </Trigger>
    282. </Style.Triggers>
    283. </Style>
    284. </UserControl.Resources>


    Der Textblock in Zeile 65 soll seinen Wert per Binding erhalten. Kann mir da einer helfen?

    Gruß
    eddi
    Hallo

    Manchesmal frage ich mich wirklich ob jemand meine Tutorials durchgeht oder nicht.

    Also...

    Du hast ja schon relativ sauber gearbeitet da du diese Combobox in ein UserControl ausgelagert hast. So sieht es jedenfalls aus.
    Aber du willst die Combobox später ja auch binden oder? Denn du musst dieser ja auch eine Itemssource mitgeben. Du kommst also eh nicht um DependencyProperties rum. Un genau im selben Prinzip machst du das mit dem Text oder dem Buchstaben der angezeigt werden soll.

    Du erstellst im CodeBehind des UserControls ein DP ​DropDownText:

    XML-Quellcode

    1. public string DropDownText
    2. {
    3. get { return (string)GetValue(DropDownTextProperty); }
    4. set { SetValue(DropDownTextProperty, value); }
    5. }
    6. // Using a DependencyProperty as the backing store for DropDownText. This enables animation, styling, binding, etc...
    7. public static readonly DependencyProperty DropDownTextProperty =
    8. DependencyProperty.Register("DropDownText", typeof(string), typeof(MyComboxBox), new PropertyMetadata("X"));


    Und dann bindest du innerhalb den Styles darauf:

    XML-Quellcode

    1. <Border x:Name="splitBorder" BorderBrush="Transparent" BorderThickness="1" HorizontalAlignment="Right" Margin="0" SnapsToDevicePixels="true" Width="{DynamicResource {x:Static SystemParameters.VerticalScrollBarWidthKey}}">
    2. <!--<Path x:Name="arrow" Data="F1 M 0,0 L 2.667,2.66665 L 5.3334,0 L 5.3334,-1.78168 L 2.6667,0.88501 L0,-1.78168 L0,0 Z" Fill="{StaticResource ComboBox.Static.Glyph}" HorizontalAlignment="Center" Margin="0" VerticalAlignment="Center"/>-->
    3. <TextBlock Text="{Binding DropDownText, Mode=OneWay, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:MyComboxBox}}}" Margin="2,2,2,2" HorizontalAlignment="Center" VerticalAlignment="Center"/>
    4. </Border>


    Ab sofort (in meinem Fall habe ich das UC MyComboBox genannt) kannst du Eigenschaft im XAML setzen oder eben auch binden:

    XML-Quellcode

    1. ​ <local:MyComboxBox DropDownText="X" ItemsSource="{Binding Source={StaticResource ListOfColors}}"/>


    Grüße
    Sascha
    If _work = worktype.hard Then Me.Drink(Coffee)
    Seht euch auch meine Tutorialreihe <WPF Lernen/> an oder abonniert meinen YouTube Kanal.

    ## Bitte markiere einen Thread als "Erledigt" wenn deine Frage beantwortet wurde. ##

    Vielen Dank erst mal.
    Tutorials ansehen und auf die passende Idee kommen ist leider oft Zweierlei. :)
    Das Video, wie man den Control eine neue Optik gibt hatte ich nochmal angesehen. Mein geändertes Control liegt aber noch im gleichen Usercontrol, in dem es auch verwendet wird. Sollte später dann in die Application als Vorlage wandern. Auf die Idee es als eigenstädiges UserControl zu erstellen und dann im CodeBehind einfach ein DP zu erstellen kam ich nicht.
    Dann leg ich mal los.

    Gruß
    eddi
    Hallo

    JA, ob du nun ein CustomControl machst oder ein UserControl ist egal, DependencyProperties können überall verwendet werden.

    Bez. Dependency Properties habe ich ein eigenes Kapitel.

    Grüße
    Sascha
    If _work = worktype.hard Then Me.Drink(Coffee)
    Seht euch auch meine Tutorialreihe <WPF Lernen/> an oder abonniert meinen YouTube Kanal.

    ## Bitte markiere einen Thread als "Erledigt" wenn deine Frage beantwortet wurde. ##