Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/262.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在C#windows store 8.1中绑定MediaElement源_C#_Xaml_Windows 8.1 - Fatal编程技术网

如何在C#windows store 8.1中绑定MediaElement源

如何在C#windows store 8.1中绑定MediaElement源,c#,xaml,windows-8.1,C#,Xaml,Windows 8.1,这个图像和标题绑定的示例是图像和标题绑定的代码,虽然我正在尝试为媒体元素绑定,但在这里不工作 public class Item : System.ComponentModel.INotifyPropertyChanged { public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged; protected virtual void OnPropertyChanged(string

这个图像和标题绑定的示例是图像和标题绑定的代码,虽然我正在尝试为媒体元素绑定,但在这里不工作

public class Item : System.ComponentModel.INotifyPropertyChanged
{
    public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;

    protected virtual void OnPropertyChanged(string propertyName)
    {
        if (this.PropertyChanged != null)
        {
            this.PropertyChanged(this, new System.ComponentModel.PropertyChangedEventArgs(propertyName));
        }
    }

    private string _Title = string.Empty;
    public string Title
    {
        get
        {
            return this._Title;
        }

        set
        {
            if (this._Title != value)
            {
                this._Title = value;
                this.OnPropertyChanged("Title");
            }
        }
    }



    private ImageSource _Image = null;
    public ImageSource Image
    {
        get
        {
            return this._Image;
        }

        set
        {
            if (this._Image != value)
            {
                this._Image = value;
                this.OnPropertyChanged("Image");
            }
        }
    }

    public void SetImage(Uri baseUri, String path)
    {
        Image = new BitmapImage(new Uri(baseUri, path));
    }


    private string _Category = string.Empty;
    public string Category
    {
        get
        {
            return this._Category;
        }

        set
        {
            if (this._Category != value)
            {
                this._Category = value;
                this.OnPropertyChanged("Category");
            }
        }
    }


public class GroupInfoList<T> : List<object>
{

    public object Key { get; set; }


    public new IEnumerator<object> GetEnumerator()
    {
        return (System.Collections.Generic.IEnumerator<object>)base.GetEnumerator();
    }
}



public class ToppingsData
{
    public ToppingsData()
    {
        Item item;
        Uri _baseUri = new Uri("ms-appx:///");

        item = new Item();
        item.Title = "Caramel Sauce";
        item.Category = "Sauces";
        item.SetImage(_baseUri, "SampleData/Images/60SauceCaramel.png");
        Collection.Add(item);

        item = new Item();
        item.Title = "Chocolate Sauce";
        item.Category = "Sauces";
        item.SetImage(_baseUri, "SampleData/Images/60SauceChocolate.png");
        Collection.Add(item);

        item = new Item();
        item.Title = "Strawberry Sauce";
        item.Category = "Sauces";
        item.SetImage(_baseUri, "SampleData/Images/60SauceStrawberry.png");
        Collection.Add(item);

        item = new Item();
        item.Title = "Chocolate Sprinkles";
        item.Category = "Sprinkles";
        item.SetImage(_baseUri, "SampleData/Images/60SprinklesChocolate.png");
        Collection.Add(item);

        item = new Item();
        item.Title = "Rainbow Sprinkles";
        item.Category = "Sprinkles";
        item.SetImage(_baseUri, "SampleData/Images/60SprinklesRainbow.png");
        Collection.Add(item);

        item = new Item();
        item.Title = "Vanilla Sprinkles";
        item.Category = "Sprinkles";
        item.SetImage(_baseUri, "SampleData/Images/60SprinklesVanilla.png");
        Collection.Add(item);

    }
    private ItemCollection _Collection = new ItemCollection();

    public ItemCollection Collection
    {
        get
        {
            return this._Collection;
        }
    }
}


// Workaround: data binding works best with an enumeration of objects that does not implement IList
public class ItemCollection : IEnumerable<Object>
{
    private System.Collections.ObjectModel.ObservableCollection<Item> itemCollection = new System.Collections.ObjectModel.ObservableCollection<Item>();

    public IEnumerator<Object> GetEnumerator()
    {
        return itemCollection.GetEnumerator();
    }

    System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
    {
        return GetEnumerator();
    }

    public void Add(Item item)
    {
        itemCollection.Add(item);
    }
}
公共类项:System.ComponentModel.INotifyPropertyChanged
{
公共事件System.ComponentModel.PropertyChangedEventHandler PropertyChanged;
受保护的虚拟void OnPropertyChanged(字符串propertyName)
{
if(this.PropertyChanged!=null)
{
this.PropertyChanged(this,new System.ComponentModel.PropertyChangedEventArgs(propertyName));
}
}
私有字符串_Title=string.Empty;
公共字符串标题
{
收到
{
返回此标题;
}
设置
{
如果(此._Title!=值)
{
这个。_Title=值;
本协议项下的不动产变更(“所有权”);
}
}
}
私有ImageSource _Image=null;
公共图像源图像
{
收到
{
返回此。\u图像;
}
设置
{
如果(此._图像!=值)
{
这个。_图像=值;
本.OnPropertyChanged(“图像”);
}
}
}
public void SetImage(Uri baseUri,字符串路径)
{
Image=新的位图图像(新的Uri(baseUri,路径));
}
私有字符串_Category=string.Empty;
公共字符串类别
{
收到
{
返回此.\u类别;
}
设置
{
如果(此._类别!=值)
{
这._类别=值;
本协议项下的不动产变更(“类别”);
}
}
}
公共类GroupInfoList:List
{
公共对象密钥{get;set;}
公共新IEnumerator GetEnumerator()
{
return(System.Collections.Generic.IEnumerator)base.GetEnumerator();
}
}
公共类数据
{
公共数据
{
项目;
Uri _baseUri=新的Uri(“ms appx://”);
项目=新项目();
item.Title=“焦糖酱”;
item.Category=“酱汁”;
SetImage(_baseUri,“SampleData/Images/60saucearamel.png”);
集合。添加(项目);
项目=新项目();
item.Title=“巧克力酱”;
item.Category=“酱汁”;
SetImage(_baseUri,“SampleData/Images/60SauceChocolate.png”);
集合。添加(项目);
项目=新项目();
item.Title=“草莓酱”;
item.Category=“酱汁”;
SetImage(_baseUri,“SampleData/Images/60SauceStrawberry.png”);
集合。添加(项目);
项目=新项目();
item.Title=“巧克力洒”;
item.Category=“Spreads”;
SetImage(_baseUri,“SampleData/Images/60schocolate.png”);
集合。添加(项目);
项目=新项目();
item.Title=“彩虹洒”;
item.Category=“Spreads”;
SetImage(_baseUri,“SampleData/Images/60springsrainbow.png”);
集合。添加(项目);
项目=新项目();
item.Title=“香草洒”;
item.Category=“Spreads”;
SetImage(_baseUri,“SampleData/Images/60springsvanilla.png”);
集合。添加(项目);
}
private ItemCollection_Collection=new ItemCollection();
公共物品收集
{
收到
{
将此返回。\u收集;
}
}
}
//解决方法:数据绑定最适用于未实现IList的对象枚举
公共类ItemCollection:IEnumerable
{
private System.Collections.ObjectModel.ObservableCollection itemCollection=新系统.Collections.ObjectModel.ObservableCollection();
公共IEnumerator GetEnumerator()
{
返回itemCollection.GetEnumerator();
}
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
{
返回GetEnumerator();
}
公共作废添加(项目)
{
itemCollection.Add(item);
}
}

我是Windows开发新手。任何和所有的帮助都将不胜感激。

我得到的答案是我们必须使用Uri类,下面是代码

私有Uri_媒体; 公共Uri媒体 { 收到 { 把这个还给我; }

        set
        {
            if (this._media != value)
            {
                this._media = value;
                this.OnPropertyChanged("Media");
            }
        }
    }

    public void SetMedia(Uri baseUri, String path)
    {
       Media = new Uri(baseUri,path);
    }