-1

私はこのように書かれたクラスを持っています

public class AudioPlayer : INotifyPropertyChanged
{

    public event PropertyChangedEventHandler PropertyChanged;
    // This method is called by the Set accessor of each property. 
    // The CallerMemberName attribute that is applied to the optional propertyName 
    // parameter causes the property name of the caller to be substituted as an argument. 
    private void NotifyPropertyChanged([CallerMemberName] String propertyName = "")
    {
        if (PropertyChanged != null)
        {
            PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
        }
    }
    [...]
    private static AudioPlayer instance = new AudioPlayer();

    public static AudioPlayer Instance { get { return instance; } }

    private Track currentTrack = null;

    // the pointer to the current track selected
    // it is useful to retrieve its new position when playlist got updates
    public Track CurrentTrack { get { return currentTrack; } 
        private set 
        { 
            currentTrack = value;
            NotifyPropertyChanged();
        } 
    }
    public class Track : ICloneable
    {
            public string Title { get; set; }
    }

xaml は次のとおりです。

    <StackPanel DataContext="{Binding Source={x:Static audiocontroller:AudioPlayer.Instance}}">
        <Label Name="lbl_bind" Content="{Binding CurrentTrack.Title}"></Label>
        <Button Name="btn" Click="btn_Click" Height="20" ></Button>
    </StackPanel>

そしてコードは機能します!

今、ModelViewコントローラーを使用して、AudioPlayerを統合したいと考えています。これを行う方法 ?

4

1 に答える 1