powered by simpleCommunicator - 2.0.18     © 2024 Programmizd 02
Map
Форумы / WPF, Silverlight [игнор отключен] [закрыт для гостей] / Как изменить картинку на кнопке комбобокса?
2 сообщений из 2, страница 1 из 1
Как изменить картинку на кнопке комбобокса?
    #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
Как изменить картинку на кнопке комбобокса?
    #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
2 сообщений из 2, страница 1 из 1
Форумы / WPF, Silverlight [игнор отключен] [закрыт для гостей] / Как изменить картинку на кнопке комбобокса?
Целевая тема:
Создать новую тему:
Автор:
Закрыть
Цитировать
Найденые пользователи ...
Разблокировать пользователей ...
Читали тему (1): Анонимы (1)
Читали форум (1): Анонимы (1)
Пользователи онлайн (10): Анонимы (7), Bing Bot, Yandex Bot, RePredeclared 7 мин.
x
x
Закрыть


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