![](/img/trans.png)
[英]Binding Visibility to Viewmodel's property [ from View To ViewModel] from CodeBehind
[英]Binding MedialElement from the view (xaml) to a ViewModel's property
我正在嘗試將Mainl.xaml的medialElement綁定到ViewModel的屬性。 在MainViewModel.cs中,我們會發現
#region Media
private MediaElement media;
public MediaElement Media
{
get
{
return media;
}
set
{
if (value == media)
return;
media = value;
OnPropertyChanged("Media");
}
}
#endregion
我想知道要放在MainView.xaml中進行綁定。
我知道如果是TextBox我會寫
`<TextBox Text="{Binding BGToSet, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}" />`
但是我應該為MediaElement做什么? 我現在這樣做:
`<MediaElement VerticalAlignment="Center" Width="700" LoadedBehavior="Manual" Height="450" Stretch="Fill" MediaOpened="{ Binding mediaMediaOpenedCommand}" >
`非常感謝您的回答! 對不起我的英語不好。 我也是WPF的新手
您應該公開要顯示的媒體源的Uri
而不是MediaElement
:
public Uri MediaSource { get { /* ... */ } set { /* ... */ } }
<MediaElement Source="{Binding MediaSource}" />
或使用ContentControl
(或ContentPresenter
)顯示MediaElement
本身:
<ContentControl Content="{Binding Media}" />
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.