Reputation: 64
I am building a tool to edit multiple database objects at the same time and am curious to get you guys' thoughts on a highlighting scheme.
In my ViewModel
, I have a collection, Juris
, of Jurisdictions
that are associated with ANY of the items a user selected to edit. I also have a sub-collection of Jurisdictions shared by ALL the selected items, "CommonJuris". My question is: Is there a simple way I can populate a ListBox
with the full collection, and highlight items that are in the sub-collection?
At the moment I have a bool property, IsCommon
, in my Jurisdiction Model
. I really don't want this in the Model
, but I haven't found a better solution yet. Jurisdiction
doesn't have a ViewModel
, as this would be the only thing in it.
Here's my XAML for the ListBox itself:
<ListBox Grid.Row="1" Grid.Column="2" ItemContainerStyle="{StaticResource JuriAndTT}"
ScrollViewer.HorizontalScrollBarVisibility="Disabled"
HorizontalContentAlignment="Stretch"
ItemsSource="{Binding Juris}">
<ListBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Name}"/>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
And the Style:
<Style TargetType="{x:Type ListBoxItem}" x:Key="JuriAndTT">
<Style.Triggers>
<DataTrigger Binding="{Binding IsCommon}" Value="True">
<Setter Property="Background" Value="PowderBlue"/>
<Setter Property="Foreground" Value="Black"/>
</DataTrigger>
</Style.Triggers>
</Style>
Upvotes: 0
Views: 189
Reputation: 57979
I think you answered this yourself -- you haven't created a view-model because it would have only one property; instead you have polluted your model with that property.
You have to weigh the two and determine whether you are more comfortable with IsCommon
in the model or with the overhead of creating a view-model.
There are some other approaches you could take, with creative use of attached properties or converters, but they will be more convoluted and difficult than just implementing the view-model.
Upvotes: 2