0
저는 WPF를 처음 접했고 MVVM 라이트를 사용하여 아주 간단한 응용 프로그램을 만들려고합니다. 내 MainWindow.xaml (보기)에서해당 속성을 기반으로 스타일 목록 항목
나는이 있습니다
InstalledVersions이 InstalledVersionViewModel 의 목록이 (간체) 내가 한 내 MainWindowResources.xaml에서입니다
<ListBox ItemsSource="{Binding InstalledVersions}"
ItemTemplate="{StaticResource VersionsDataTemplate}"
Style="{StaticResource VersionsStyle}"
ItemContainerStyle="{StaticResource VersionItemStyle}"/>
:
<DataTemplate x:Key="VersionsDataTemplate"
DataType="{x:Type viewmodels:InstalledVersionViewModel}">
<Grid>
<TextBlock Text="{Binding VersionNumber}" />
<TextBlock Text="{Binding FolderPath}" />
</Grid>
</DataTemplate>
<Style x:Key="VersionsStyle"
TargetType="{x:Type ListBox}">
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
<Setter Property="VerticalContentAlignment" Value="Center" />
</Style>
<Style x:Key="VersionItemStyle"
TargetType="{x:Type ListBoxItem}">
<Setter Property="Background" Value="White" />
</Style>
가
내 InstalledVersionViewModel의 "IsActive"속성에 따라 다른 배경을 갖고 싶습니다.
<Style.Triggers>
<Trigger Property="{Binding Path=DataContext.IsActive, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type viewmodels:InstalledVersionViewModel}}}" Value="True">
<Setter Property="Background" Value="Red" />
</Trigger>
</Style.Triggers>
: (I 의심으로 주로 내가 뭘하는지 이해하지 않기 때문에,)
나는 그것이 작동하지 않는 내 VersionItemStyle이 (뿐만 아니라 그것의 몇 가지 변화를) 추가하려고하지만,
감사! IsActive
이후
으로, 감사 것을 달성 할 수있는 각 행에 대한 뷰 모델의 일부입니다! – thomasb