<ListBox x:Name="lbMailShots" ItemsSource="{Binding MessageOrderedList}" Grid.Row="1" ScrollViewer.HorizontalScrollBarVisibility="Disabled" > <i:Interaction.Triggers> <i:EventTrigger EventName="SelectionChanged"> <i:InvokeCommandAction Command="{Binding EmailShotSelectionChangedCommand}" CommandParameter="{Binding ElementName=lbMailShots}" /> </i:EventTrigger> </i:Interaction.Triggers> <ListBox.ItemTemplate> <ItemContainerTemplate> <Grid> <Grid.RowDefinitions> <RowDefinition ></RowDefinition> <RowDefinition ></RowDefinition> </Grid.RowDefinitions> <Grid.ColumnDefinitions> <ColumnDefinition x:Name="cdMailShot"></ColumnDefinition> </Grid.ColumnDefinitions> <TextBlock x:Name="tbMailSubject" Grid.Row="0" Text="{Binding Path=Subject}" TextTrimming="CharacterEllipsis" FontSize="14" Padding="0, 10, 0 0" TextWrapping="NoWrap"></TextBlock> <TextBlock x:Name="tbMailBodyShot" Grid.Row="1" Text="{Binding Path=BodyShot}" TextTrimming="CharacterEllipsis" FontSize="12" Foreground="#777" Padding="0, 0,0,10" TextWrapping="NoWrap"></TextBlock> </Grid> </ItemContainerTemplate> </ListBox.ItemTemplate> </ListBox>
<WebBrowser x:Name="wbMailBody" />
private ICommand emailShotSelectionChangedCommand; public ICommand EmailShotSelectionChangedCommand { get { if (this.emailShotSelectionChangedCommand == null) this.emailShotSelectionChangedCommand = new DelegateCommand(x => this.EmailShotSelectionChanged(x)); return this.emailShotSelectionChangedCommand; } } private void EmailShotSelectionChanged(object o) { var listbox = o as ListBox; if (listbox.SelectedItem == null) return; var vodel = listbox.SelectedItem as MessageListBoxItemModel; var path = System.IO.Path.Combine(SystemConfiguration.Eml.Folder, vodel.EmlNameWithExtension); var msg = Mail_Message.ParseFromFile(path);
// 这个wbMailBody 是个WebBrowser控件,在ViewModel类里看不到这个控件
// 所以这行代码报错。请问MVVM怎么解决这样的问题
this.wbMailBody.NavigateToString(msg.BodyHtmlText.WrapsWithHtmlTag()); }
建议题主先再多看几本有关MVVM的书,你在代码里面访问控件,这算啥MVVM啊
我是真不知道如何传递参数了,比如treeview里的节点点击后,想把绑定的model传到viewmodel里,怎么搞?
Dispatcher.Invoke(new Action(()=> { this.wbMailBody.NavigateToString(msg.BodyHtmlText.WrapsWithHtmlTag()); }));
这个代码是写在哪里的?
以为是多线程问题呢
写个事件,看得见这个控件的地方去响应
XAML中没有wbMailBody控件。请重新贴代码。
绑定命令直接更改 直接就会体现出来