2011-04-02 8 views
1

私はリストボックスが私のChange the Selected Color Listbox質問で述べた修正と私はアイテムの例外を選択し、これまでときthrown.Itの読み取りでスロー修正リストボックスには、例外

'{DependencyProperty.UnsetValue}' is not a valid value for property 'Background'. 

私が間違っ

使用のXmaI

<ListBox ItemContainerStyle="{StaticResource ListBoxItemStyle1}" Width="300" Height="519" Name="listFriends" HorizontalAlignment="Left" VerticalAlignment="Center" > 
    <ListBox.Items> 
     <StackPanel Width="289" Orientation="Horizontal" > 
     <Image Margin="0,0,4,0" Height="50" Width="50" Source="{Binding Picture}" /> 
     <my:RibbonCheckBox Label="test" IsChecked="{Binding IsChecked}"/> 
     </StackPanel> 
     <StackPanel Width="289" Orientation="Horizontal" > 
      <Image Margin="0,0,4,0" Height="50" Width="50" Source="{Binding Picture}" /> 
      <my:RibbonCheckBox Height="20" Label="test" IsChecked="{Binding IsChecked}" Foreground="White" /> 
     </StackPanel> 
     <StackPanel Width="289" Orientation="Horizontal" > 
      <Image Margin="0,0,4,0" Height="50" Width="50" Source="{Binding Picture}" /> 
      <my:RibbonCheckBox Height="20" Label="test" IsChecked="{Binding IsChecked}" Foreground="White" /> 
     </StackPanel> 
    </ListBox.Items> 
</ListBox> 
をやっている何を

スタイル変更済み

<Style x:Key="ListBoxItemStyle1" TargetType="{x:Type ListBoxItem}"> 
    <Setter Property="Background" Value="Transparent"/> 
    <Setter Property="HorizontalContentAlignment" Value="{Binding HorizontalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}"/> 
    <Setter Property="VerticalContentAlignment" Value="{Binding VerticalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}"/> 
    <Setter Property="Padding" Value="2,0,0,0"/> 
    <Setter Property="Template"> 
     <Setter.Value> 
      <ControlTemplate TargetType="{x:Type ListBoxItem}"> 
       <Border x:Name="Bd" BorderBrush="{TemplateBinding BorderBrush}" 
     BorderThickness="{TemplateBinding BorderThickness}" 
     Background="{TemplateBinding Background}" 
     Padding="{TemplateBinding Padding}" SnapsToDevicePixels="true" CornerRadius="10" 
     > 
        <ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/> 
       </Border> 
       <ControlTemplate.Triggers> 
        <Trigger Property="IsSelected" Value="true"> 
         <Setter Property="Background" TargetName="Bd" Value="{StaticResource GrBrush}"/> 
         <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.HighlightTextBrushKey}}"/> 
        </Trigger> 

        <MultiTrigger> 
         <MultiTrigger.Conditions> 
          <Condition Property="IsSelected" Value="true"/> 
          <Condition Property="Selector.IsSelectionActive" Value="false"/> 
         </MultiTrigger.Conditions> 
         <Setter Property="Background" TargetName="Bd" Value="{StaticResource GradientBrush}"/> 
         <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/> 
        </MultiTrigger> 
        <Trigger Property="IsEnabled" Value="false"> 
         <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/> 
        </Trigger> 
       </ControlTemplate.Triggers>       
      </ControlTemplate>      
     </Setter.Value>     
    </Setter>    
</Style> 
+1

を発生した理由であることに異なっていたと宣言ということでしたXAMLスニペット?あなたの束縛が予期しない結果を生み出しているようです。 –

+0

編集した質問 –

+0

を参照してください。GrBrushとGradientブラシが合法であると仮定すると、これはうまく見えます。この問題がXAMLのスニペットから来ていることと、Backgroundプロパティと対話するコードがないことを100%確信していますか? –

答えて

0

問題は、私はあなたが完全を投稿することができ

GrBrushで

<Setter Property="Background" TargetName="Bd" Value="{StaticResource GradientBrush}"/> 

のように使用

<LinearGradientBrush x:Key="GrBrush" EndPoint="0.5,1" StartPoint="0.5,0"> 
      <GradientStop Color="#FF6BB9E8" Offset="0" /> 
      <GradientStop Color="#541882CE" Offset="1" /> 
     </LinearGradientBrush> 

と使用方法は、エラーが

関連する問題