c# - WPF trigger for selected items -


I am using the MVVM lighting framework. On one of my pages, I have a list box that contains a bound list And one bound is the selected item. I have a style that should highlight the selected items in that list box. However, this item is not highlighted unless I physically click it (this item will not be binding only).

XAML:

  & lt; UserControl.Resources & gt; & Lt; HartWom: View Locator x: Key = "HeartWillLoocessor" D: Icedatasource = "True" /> & Lt; DataTemplate DataType = "{x: Type Excerpt: QuotePummSummaryItem}" & gt; & Lt; View: Quote: SocialitiumDatacontex = "{Binding}" /> & Lt; / DataTemplate & gt; & Lt; Style x: key = "ListboxItemStyle" TargetType = "{x: type listbox ITM}" & gt; & Lt; Style.Resources & gt; & Lt; Solid Colorebrush X: Key = "{x: Static System Colors. Highlight Brushes}" Color = "Red" /> & Lt; Solid Coiler Brush x: Key = "{x: Static System Colors. Highlight TextWorld}" Color = "Black" /> & Lt; /Style.Resources> & Lt; Setter Property = "Borderbrush" value = "Red" /> & Lt; Style.Triggers & gt; & Lt; Trigger property = "isleded" value = "wrong" & gt; & Lt; Setter Property = "BorderTitches" value = "0" /> & Lt; Setter Property = "Opacity" value = "40" /> & Lt; / Catalyst & gt; & Lt; Trigger Property = "Iceded" value = "true" & gt; & Lt; Setter property = "borderline" value = "1" /> & Lt; Setter property = "opacity" value = "100" /> & Lt; / Catalyst & gt; & Lt; /Style.Triggers> & Lt; / Style & gt; & Lt; /UserControl.Resources> & Lt; UserControl.DataContext & gt; & Lt; Binding source = "{static resource heartville locator}" path = "quotation tool" /> & Lt; /UserControl.DataContext> & Lt; Border & gt; & Lt; Grid & gt; & Lt; Grid.RowDefinitions & gt; & Lt; RowDefinition Height = "Auto" /> & Lt; RowDefinition / & gt; & Lt; /Grid.RowDefinitions> & Lt; Border borderbrush = "black" borderchurch = "0" & ​​gt; & Lt; TextBlock TextWrapping = "wrap" text = "quotation summary" margin = "5,0,0,0" fontSize = "21.333" foreground = "{DynamicResource ControlHeaderBrush}" FontFamily = "Verdana" /> & Lt; / Border & gt; & Lt; ScrollViewer D: Layout Override = "Height" Scroll Weaver. Horizontal Sokalberviewjility = "Auto" Scrollviewer. VerticalScrollability = "Auto" Grid. Raw = "1" margin = "10,10,5,10" & gt; & Lt; Taylor: RadBusyIndicator IsBusy = "{Binding ISProcessing}" & gt; & Lt; ListBox ItemsSource = "{Binding DefaultList}" selectedItem = "{binding select default}" background = "{x: faucet}" item container style = "{static resource list box style}" & gt; & Lt; ListBox.ItemsPanel & gt; & Lt; ItemsPanelTemplate & gt; & Lt; WrapPanel Orientation = "horizontal" /> & Lt; / ItemsPanelTemplate & gt; & Lt; /ListBox.ItemsPanel> & Lt; / ListBox & gt; & Lt; / Telerik: RadBusyIndicator & gt; & Lt; / ScrollViewer & gt; & Lt; / Grid & gt; & Lt; / Border & gt; & Lt; / UserControl & gt;   

Code (choose the item in the list box in the program):

  public QuoteSummaryItem SelectedDefault {get; Set; } Private Zero selectDefault () {If (DefaultList == zero} DefaultList.First (). Pet == Faucet) Return; SelectedDefault = DefaultList.First (); MessengerService.Send (SelectionMessage.Create (SelectedDefault.SubDefault)); }   

The message being sent is not important and some other works on the second page. The selected default asset is the only thing that is used for this example.

What do I need to do to get this job done?

It looks like binding (and thus your idea) that the selected item property has changed.

The default selected requires you to make an alert by using the INotifyPropertyChanged interface.

I just took a quick look at the MVVM lighting framework and decided on the basis of the samples, if your view is obtained from the modem view Modelbase which uses the field backed property and call RaisePropertyChanged:

  private quotePetSummaryItem _selectedDefault; Public quotespath moderator selected default {get {return_selectedDefault; } Set {_selectedDefault = value; RaisePropertyChanged ("SelectedDefault"); }}    

Comments