可能非常簡單,但我無法找到需要更改哪些代碼才能使其工作。我的媒體位看起來是這樣的:一個播放按鈕正在控制所有其他按鈕動作WPF
當我點擊任何其他所有的三個按鈕藏漢改變按鈕的發揮。
public void ButtonPlay1_OnClick(object sender, RoutedEventArgs e)
{
var context = DataContext as PlayButton.SampleContext;
if (context == null)
return;
context.IsPlaying = !context.IsPlaying;
}
public void ButtonPlay2_OnClick(object sender, RoutedEventArgs e)
{
var context = DataContext as PlayButton.SampleContext;
if (context == null)
return;
context.IsPlaying = !context.IsPlaying;
}
public void ButtonPlay3_OnClick(object sender, RoutedEventArgs e)
{
var context = DataContext as PlayButton.SampleContext;
if (context == null)
return;
context.IsPlaying = !context.IsPlaying;
}
有我的三個不同的按鈕按鈕點擊事件。我有一類是BoolToVisabilityConverter,也稱爲PLAYBUTTON類,它只是檢查是否按鈕被打,這是什麼在PLAYBUTTON類:
public partial class PlayButton : xamlNewAudit
{
public PlayButton()
{
InitializeComponent();
DataContext = new SampleContext();
}
public class SampleContext : INotifyPropertyChanged
{
private bool _isPlaying;
public bool IsPlaying
{
get { return _isPlaying; }
set
{
if (_isPlaying == value)
return;
_isPlaying = value;
OnPropertyChanged("IsPlaying");
}
}
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void OnPropertyChanged(string propertyName)
{
var handler = PropertyChanged;
if (handler != null)
handler(this, new PropertyChangedEventArgs(propertyName));
}
編輯:對不起了簡短的解釋,我只是想所以當我點擊其中一個按鈕時,其他兩個按鈕暫停播放。
編輯:按鈕的Xaml代碼是;
<Button x:Name="ButtonPlay" Height="45" Click="ButtonPlay1_OnClick" Margin="-2,0,57,60" DockPanel.Dock="Top">
<Button.Template>
<ControlTemplate TargetType="{x:Type Button}">
<Grid>
<Ellipse Stroke="Black" />
<Image Source="Images/PlayButton.png" Visibility="{Binding IsPlaying, ConverterParameter={x:Static Visibility.Hidden}, Converter={Application:BoolToVisibilityConverter}}" />
<Image Source="Images/pauseButton.png" Visibility="{Binding IsPlaying, ConverterParameter={x:Static Visibility.Visible}, Converter={Application:BoolToVisibilityConverter}}" />
</Grid>
</ControlTemplate>
</Button.Template>
</Button>
這是第一個按鈕的XAML代碼,其他按鈕的代碼是相同的,除了點擊事件鏈接到不同的方法。
我想你可能想澄清你的問題。 – Inisheer
我可以使用按鈕的xaml代碼嗎? –
@Inisheer我在底部添加了編輯,很抱歉給出了簡要解釋。 –