blend2009. 1. 29. 11:13
datagrid와 좀 다르게 listbox를 바꿀수 있지만 datagrid가 더 나은듯하다... 

app,xaml 이나 해당 xaml에 이걸 추가한다

<Style x:Key="listBoxItemStyle" TargetType="{x:Type ListBoxItem}">
 <Style.Resources>
  <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}"
   Color="Gray"/>
 </Style.Resources>  
</Style>

여기서 SystemColors.HighlightBrushKey 에 있는 color를 써야한다. 그렇게 하지 않고 rgb를 쓰면 투명도가 설정되어 있지않아

선택된 값이 보이지 않는다...

cs에서 하는 방법이 있긴하다 아래처럼

//색상을 생성
   SolidColorBrush brush = new SolidColorBrush(Colors.Green);
//투명도를 20%로
   brush.Opacity = 0.2;
//LIstBox Control의 Resource로 등록 SystemColors.HighlightBrushKey는 하이라이트 색상을 빨강으로 함....
   _list.Resources.Add(SystemColors.HighlightBrushKey, brush);
   _list.Resources.Add(SystemColors.HighlightTextBrushKey, new SolidColorBrush(Colors.Black));

하지만 xaml딴에서 해결하는게 나을듯하다.

listbox에 적용할때는

<ListBox IsSynchronizedWithCurrentItem="True" HorizontalAlignment="Stretch" Grid.ColumnSpan="1" Height="Auto" x:Name="listAlarmCameraList" DisplayMemberPath="strCameraName" Grid.Row="1" Style="{DynamicResource csListBox}"  ItemContainerStyle="{StaticResource listBoxItemStyle}"/>

이부분을 추가하면된다.
 ItemContainerStyle="{StaticResource listBoxItemStyle}"


text로 바꿀수 있는방법을 찾았다..ㅋㅋ

<ListBox> 
<ListBox.Resources> 
<SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="White"/> 
<SolidColorBrush x:Key="{x:Static SystemColors.HighlightTextBrushKey}" Color="Black"/> 
<SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}" Color="White"/> 
</ListBox.Resources> 
</ListBox> 

controlBrushkey는 disable이거나 focus가 다른쪽으로 갔을때 색이다.

Posted by 동동(이재동)