2012-07-17 83 views
7

因此,我試圖在Expression blend中更改我的組合框的樣式。更改WPF組合框的邊框顏色

我所做的就是創建一個組合框,就去點擊右鍵>編輯模板>編輯複製

而且我可以改變組合框的顏色,除了有在背景之間的白色邊界的組合框,以及組合框的邊界。這裏是一個屏幕,所以你可以看到:

enter image description here

正如你所看到的,有藍色和紅色之間的邊界時。據我所知道的,代碼改變組合框的顏色如下:

<ToggleButton Grid.ColumnSpan="2" IsChecked="{Binding IsDropDownOpen, Mode=TwoWay, 
RelativeSource={RelativeSource TemplatedParent}}" Style="{StaticResource 
ComboBoxReadonlyToggleButton}" BorderBrush="Red" Background="Blue"/> 

但無論怎樣,總有一個白色邊框。我如何擺脫它?

回答

0

問題是,當您編輯副本時,您正在使用Microsoft內置chrome組件編輯副本。爲了更改外部邊界,您需要用普通的WPF控件替換這些位,以便可以更改這些值。對於組合框,你想使用這裏的代碼:http://msdn.microsoft.com/en-us/library/ms752094

E:這是你想要編輯

<Border x:Name="Border" 
     Grid.ColumnSpan="2" 
     CornerRadius="2" 
     BorderThickness="1"> 
    <Border.BorderBrush> 
    <LinearGradientBrush EndPoint="0,1" 
         StartPoint="0,0"> 
     <GradientStop Color="{DynamicResource BorderLightColor}" 
        Offset="0" /> 
     <GradientStop Color="{DynamicResource BorderDarkColor}" 
        Offset="1" /> 
    </LinearGradientBrush> 
    </Border.BorderBrush> 
1

我知道這是一個老問題的一部分,它是專門針對混合但當用Google搜索這個問題,這是我發現的第一件事情之一。

解決這個問題的一個非常簡單的例子是,比提到的第一個答案稍微簡單一點的是設置「樣式」屬性。 (不知道這適用於混合,因爲我不使用混合,但對於簡單的WPF在視覺工作室,這工作)

例如,下面的代碼創建一個窗口就像問題中提到的一個,但與白線(在下拉項目中)可編輯。

<ComboBox Background="Blue" BorderBrush="Red"> 
    <ComboBox.ItemContainerStyle> 
     <!-- Without this style section, there are white lines around the borders. Even if you set these properties in the comboBoxItem areas --> 
     <Style TargetType="ComboBoxItem"> 
      <Setter Property="Background" Value="Green"/> 
      <Setter Property="BorderBrush" Value="Purple"></Setter> 
     </Style> 
    </ComboBox.ItemContainerStyle> 
    <ComboBoxItem MouseMove="schedule" Name="cbi1">schedule</ComboBoxItem> 
</ComboBox>