Гость
Форумы / WPF, Silverlight [игнор отключен] [закрыт для гостей] / Как изменить картинку на кнопке комбобокса? / 2 сообщений из 2, страница 1 из 1
15.12.2021, 09:48
    #40120157
beowulf_21_x
Гость
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Как изменить картинку на кнопке комбобокса?
Есть комбобокс. На нем надо сделать стрелочку поострее. Остальное - не интересует, что-то пусть будет как есть, что-то стилями кастомизировать можно.
Пока есть такой xaml из стакероверфлоу:
Код: xml
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
45.
46.
47.
48.
49.
50.
51.
52.
53.
54.
55.
56.
57.
58.
59.
 <ComboBox.Template>
                            <ControlTemplate TargetType="{x:Type ComboBox}">
                                <Grid>
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="*"/>
                                        <ColumnDefinition Width="Auto"/>
                                    </Grid.ColumnDefinitions>
 
                                    <TextBox IsReadOnly="True" Grid.ColumnSpan="2" Cursor="Arrow" AutoWordSelection="False"  Background="White" BorderThickness="1" Text="{Binding SelectedItem.Value, Mode=OneWay, RelativeSource={RelativeSource TemplatedParent}}"  />
 
                                    <ToggleButton Width="20" Height="18" Grid.Column="1" Margin="0,2,2,2"   ClickMode="Press" Focusable="False" BorderBrush="Transparent" Background="Transparent"
                                         IsChecked="{Binding IsDropDownOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}">
                                        
                                        <ToggleButton.Template>
                                            <ControlTemplate TargetType="{x:Type ToggleButton}">
                                                <!-- Triggers of ToggleButton -->
                                                <ControlTemplate.Triggers>
                                                    <Trigger Property="IsChecked" Value="true" >
                                                        <Setter Property="Background" Value="White" />
                                                    </Trigger>
                                                </ControlTemplate.Triggers>
                                                <!-- Triangle -->
                                                <Path HorizontalAlignment="Center" VerticalAlignment="Top" Margin="5,5,5,5" Data="M 0 0 L 4 9 L 8 0 Z" >
                                                    <Path.Fill>
                                                        <SolidColorBrush Color="Black"/>
                                                    </Path.Fill>
                                                    <Path.Triggers>
 
                                                    </Path.Triggers>
 
                                                </Path>
                                                
                                            </ControlTemplate>                                          
                                        
                                        </ToggleButton.Template>
                                    </ToggleButton>
                                    <Popup x:Name="Popup" Placement="Bottom" IsOpen="{TemplateBinding IsDropDownOpen}" AllowsTransparency="True" Focusable="False" PopupAnimation="Slide">
                                        <Grid x:Name="DropDown" SnapsToDevicePixels="True" MinWidth="{TemplateBinding ActualWidth}" MaxHeight="{TemplateBinding MaxDropDownHeight}">
                                            <Border x:Name="DropDownBorder" BorderThickness="1">
                                                <Border.BorderBrush>
                                                    <SolidColorBrush Color="{TemplateBinding BorderBrush}" />
                                                </Border.BorderBrush>
                                                <Border.Background>
                                                    <SolidColorBrush Color="White" />
                                                </Border.Background>
                                            </Border>
                                            <!--  -->
                                            <ScrollViewer Margin="2,2,2,2" SnapsToDevicePixels="True">
                                                <StackPanel  IsItemsHost="True" KeyboardNavigation.DirectionalNavigation="Contained">
                                                    <StackPanel.Resources>
                                                        <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="#009DDB"/>
                                                    </StackPanel.Resources>
                                                </StackPanel>
                                            </ScrollViewer>
                                        </Grid>
                                    </Popup>
                                </Grid>
                            </ControlTemplate>
                        </ComboBox.Template>


Как из него достать только кнопарик а с остальным не возиться?
...
Рейтинг: 0 / 0
15.12.2021, 11:02
    #40120172
Сон Веры Павловны
Участник
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Как изменить картинку на кнопке комбобокса?
beowulf_21_x
Как из него достать только кнопарик а с остальным не возиться?

Код: c#
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
static class VisualTreeHelperEx
{
  public static IEnumerable<T> FindVisualChildren<T>(this DependencyObject root)
  where T: Visual
  {
    if (root==null)
      yield break;
    for(var i=0; i<VisualTreeHelper.GetChildrenCount(root);i++)
    {
      var child = VisualTreeHelper.GetChild(root, i);
      if (child is T t)
        yield return t;
      foreach (var childOfChild in FindVisualChildren<T>(child))
        yield return childOfChild;
    }
  }
}


Код: c#
1.
2.
3.
4.
5.
6.
7.
void MainWindowLoaded(object sender, RoutedEventArgs e)1
{
  var path = MyComboBox.FindVisualChildren<Path>().FirstOrDefault();
  if (path == null) return;
  path.Data = Geometry.Parse("M 0 0 L 3.5 6 L 7 0 Z");
  path.Fill = Brushes.Red;
}
...
Рейтинг: 0 / 0
Форумы / WPF, Silverlight [игнор отключен] [закрыт для гостей] / Как изменить картинку на кнопке комбобокса? / 2 сообщений из 2, страница 1 из 1
Целевая тема:
Создать новую тему:
Автор:
Найденые пользователи ...
Разблокировать пользователей ...
Читали форум (0):
Пользователи онлайн (0):
x
x
Закрыть


Просмотр
0 / 0
Close
Debug Console [Select Text]