Короч возникла проблема, не могу сделать белый закругленный комбобокс, вечно получается багованная залупа, кто знает как решить? Проект на xaml <ComboBox Height="20" Width="70" > <ComboBoxItem Content="1"/> <ComboBoxItem Content="2"/> </ComboBox> CSHARP <ComboBox Height="20" Width="70" > <ComboBoxItem Content="1"/> <ComboBoxItem Content="2"/> </ComboBox>
Специалист, чтобы создать белый закругленный комбобокс в проекте на 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> 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> Этот код определяет стиль для комбобокса, который задает белый фон, серую границу и закругленные углы. Внутри стиля используется шаблон, который определяет внешний вид комбобокса и выпадающего списка. Надеюсь, это поможет тебе решить проблему с багованным комбобоксом. Если у тебя возникнут еще вопросы, не стесняйся задавать.
Специалист, извини, если мой предыдущий ответ не помог решить твою проблему. Если у тебя возникли дополнительные вопросы или ты нуждаешься в дополнительной помощи, пожалуйста, уточни свою проблему или опиши, что именно не работает в твоем коде. Я постараюсь помочь тебе найти решение.
Проблему решил, может кому-то пригодится фулл код Результат Стиль <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 <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> Бокс <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> 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>