1
我有兩個元素,一個WebBrowser和一個滑塊,我試圖隱藏一個和顯示另一個取決於用戶打開哪種類型的文檔,一個PDF或視頻文件(mp4)。但是,目前,當我打開PDF文件時,WebBrowser仍然處於隱藏狀態。WPF - 設置Web瀏覽器不工作的代碼背後的可見性
在MainWindow.xaml,我有
<WebBrowser x:Name="PDFView" Width="600"
Height="410" Visibility="{Binding PDFVisible}">
</WebBrowser>
<FFmpegFramework:MediaElement Grid.Row="0" x:Name="MediaElement"
Height="400" Background="Gray" Visibility="{Binding VideoVisible}"/>
在MainWindow.xaml.cs,我有
else if (fileName.Contains("pdf"))
{
MainWindowViewModel dataContext = this.DataContext as MainWindowViewModel;
dataContext.PDFVisible = Visibility.Visible;
dataContext.VideoVisible = Visibility.Collapsed;
//PDFView.Navigate("file:///" + fileName);
}
else if (fileName.Contains("mp4"))
{
MainWindowViewModel dataContext = this.DataContext as MainWindowViewModel;
dataContext.PDFVisible = Visibility.Collapsed;
dataContext.VideoVisible = Visibility.Visible;
}
在MainWindowModel.cs,我有:
public Visibility PDFVisible
{
get
{
return fPDFVisible;
}
set
{
this.SetProperty<Visibility>(ref fPDFVisible, value);
}
}
public Visibility VideoVisible
{
get
{
return fVideoVisible;
}
set
{
this.SetProperty<Visibility>(ref fVideoVisible, value);
}
}
private Visibility fPDFVisible = Visibility.Collapsed;
private Visibility fVideoVisible = Visibility.Visible;
是否mainviewmodel執行INotifyPropertyChanged? – Krishna
它實現了BindableBase,我剛剛查找並實現INotifyPropertyChanged –
btw爲什麼要在xaml.cs中進行更改,而不是在視圖模型中進行更改? – Krishna