Загрузка...

White rounded combobox

Thread in C# created by Специалист Nov 19, 2023. 134 views

  1. Специалист
    Специалист Topic starter Nov 19, 2023 10,347 Mar 4, 2018
    Короч возникла проблема, не могу сделать белый закругленный комбобокс, вечно получается багованная залупа, кто знает как решить?
    Проект на xaml
    [IMG]
    CSHARP
    <ComboBox Height="20" Width="70" >
    <ComboBoxItem Content="1"/>
    <ComboBoxItem Content="2"/>
    </ComboBox>
     
  2. ChatGPT
    ChatGPT Nov 19, 2023 2250 Mar 14, 2023
    Специалист, чтобы создать белый закругленный комбобокс в проекте на XAML, тебе понадобится использовать стили и шаблоны. Вот пример кода, который ты можешь использовать:

    XAML

    <ComboBox Height="20" Width="70">
    <ComboBox.Resources>
    <Style TargetType="ComboBox">
    <Setter Property="Background" Value="White"/>
    <Setter Property="BorderBrush" Value="Gray"/>
    <Setter Property="BorderThickness" Value="1"/>
    <Setter Property="Padding" Value="5"/>
    <Setter Property="Template">
    <Setter.Value>
    <ControlTemplate TargetType="ComboBox">
    <Grid>
    <ToggleButton x:Name="ToggleButton"
    BorderBrush="{TemplateBinding BorderBrush}"
    BorderThickness="{TemplateBinding BorderThickness}"
    Background="{TemplateBinding Background}"
    Padding="{TemplateBinding Padding}">
    <ContentPresenter />
    </ToggleButton>
    <Popup x:Name="Popup"
    IsOpen="{TemplateBinding IsDropDownOpen}"
    Placement="Bottom"
    AllowsTransparency="True"
    Focusable="False">
    <Border x:Name="PopupBorder"
    Background="White"
    BorderBrush="Gray"
    BorderThickness="1"
    CornerRadius="5">
    <ScrollViewer>
    <ItemsPresenter />
    </ScrollViewer>
    </Border>
    </Popup>
    </Grid>
    </ControlTemplate>
    </Setter.Value>
    </Setter>
    </Style>
    </ComboBox.Resources>
    <ComboBoxItem Content="1"/>
    <ComboBoxItem Content="2"/>
    </ComboBox>
    Этот код определяет стиль для комбобокса, который задает белый фон, серую границу и закругленные углы. Внутри стиля используется шаблон, который определяет внешний вид комбобокса и выпадающего списка.

    Надеюсь, это поможет тебе решить проблему с багованным комбобоксом. Если у тебя возникнут еще вопросы, не стесняйся задавать.
     
    1. Специалист Topic starter
      ChatGPT, нихуя себе, ну и залупа
    2. ChatGPT
      Специалист, извини, если мой предыдущий ответ не помог решить твою проблему. Если у тебя возникли дополнительные вопросы или ты нуждаешься в дополнительной помощи, пожалуйста, уточни свою проблему или опиши, что именно не работает в твоем коде. Я постараюсь помочь тебе найти решение.
  3. Специалист
    Специалист Topic starter Nov 19, 2023 10,347 Mar 4, 2018
    Проблему решил, может кому-то пригодится
    фулл код
    Результат
    [IMG] [IMG]
    CSHARP
    <Style x:Key="CustomComboBox" TargetType="ComboBox">
    <Setter Property="Foreground" Value="#FF120F0F"/>
    <Setter Property="Background" Value="White"/>
    <Setter Property="BorderBrush" Value="#FFCCCCCC"/>
    <Setter Property="BorderThickness" Value="1.20"/>
    <Setter Property="Padding" Value="0"/>
    <Setter Property="Template">
    <Setter.Value>
    <ControlTemplate TargetType="ComboBox">
    <Border CornerRadius="4"
    Background="{TemplateBinding Background}"
    BorderBrush="{TemplateBinding BorderBrush}"
    BorderThickness="{TemplateBinding BorderThickness}">
    <Grid>
    <ToggleButton Name="ToggleButton"
    Grid.Column="2"
    ClickMode="Press"
    Focusable="false"
    IsChecked="{Binding IsDropDownOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}">
    <ToggleButton.Template>
    <ControlTemplate TargetType="ToggleButton">
    <Border Name="Border"
    CornerRadius="4"
    Background="Transparent"
    BorderBrush="Transparent">
    <Path x:Name="Arrow"
    Fill="#FF5D5959"
    HorizontalAlignment="Right"
    VerticalAlignment="Center"
    Margin="0,0,5,0"
    Data="M 0 0 L 4 4 L 8 0 Z"/>
    </Border>
    </ControlTemplate>
    </ToggleButton.Template>
    </ToggleButton>
    <ContentPresenter Name="ContentSite"
    IsHitTestVisible="False"
    Content="{TemplateBinding SelectionBoxItem}"
    ContentTemplate="{TemplateBinding SelectionBoxItemTemplate}"
    ContentTemplateSelector="{TemplateBinding ItemTemplateSelector}"
    VerticalAlignment="Center"
    HorizontalAlignment="Center"/>
    <Popup Name="Popup"
    Placement="Bottom"
    IsOpen="{TemplateBinding IsDropDownOpen}"
    AllowsTransparency="True"
    Focusable="False"
    PopupAnimation="Slide">
    <Grid Name="DropDown"
    SnapsToDevicePixels="True"
    MinWidth="{TemplateBinding ActualWidth}"
    MaxHeight="{TemplateBinding MaxDropDownHeight}">
    <Border x:Name="DropDownBorder"
    Background="White"
    BorderThickness="1"
    BorderBrush="#FFDEDEDE"/>
    <ScrollViewer Margin="4,6,4,6"
    SnapsToDevicePixels="True">
    <StackPanel IsItemsHost="True"
    KeyboardNavigation.DirectionalNavigation="Contained"/>
    </ScrollViewer>
    </Grid>
    </Popup>
    </Grid>
    </Border>
    </ControlTemplate>
    </Setter.Value>
    </Setter>
    </Style>

    CSHARP
    <ComboBox Width="70"  Height="20" Style="{StaticResource CustomComboBox}" Margin="0,0,0,10">
    <ComboBoxItem Content="1"/>
    <ComboBoxItem Content="2"/>
    <ComboBoxItem Content="15"/>
    <ComboBoxItem Content="20"/>
    <ComboBoxItem Content="10"/>
    </ComboBox>
     
Loading...
Top