<UserControl
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
x:Class="Menupedia.MiniRestaurantViewer"
x:Name="UserControl" Width="80" Height="100">
<Grid x:Name="LayoutRoot">
<Label x:Name="label_Name" Content="{Binding _name, Mode=OneWay}" HorizontalAlignment="Stretch" Width="80" FontFamily="Public Enemy NF" FontSize="14.667" Foreground="#FFEF7B54" Margin="0" Height="20" VerticalAlignment="Bottom"/>
<Image x:Name="image_Logo" Source="{Binding _logo, Mode=OneWay}" HorizontalAlignment="Left" Width="80" Height="80" VerticalAlignment="Top"/>
<Border BorderBrush="#FFF15A28" BorderThickness="1" Height="80" CornerRadius="2" VerticalAlignment="Top" Width="80" HorizontalAlignment="Left"/>
</Grid>
public partial class MiniRestaurantViewer : UserControl
{
public int _id {get{return id;}}
public string _name {get{return name;}}
public ImageSource _logo {get{return logo;}}
public MiniRestaurantViewer(int id, string name,byte[] logo)
{
this.id = id;
this.name = name;
this.logo = ByteArrayToImageSource(logo);
this.InitializeComponent();
}
private int id;
private string name;
private ImageSource logo;
private ImageSource ByteArrayToImageSource(byte[] data)
{
BitmapImage image = null;
if (null != data)
{
image = new BitmapImage();
image.BeginInit();
image.StreamSource = new System.IO.MemoryStream(data);
image.EndInit();
}
return image;
}
public MiniRestaurantViewer()
{
this.InitializeComponent();
}
}
這是我的自定義控制。我想這樣做
ListBox.Items.Add(new MiniRestaurantViewer(1,"test",null));
當我這樣做,我看到的UI元素,但它是空的(綁定不起作用)。通過手錶,雖然我發現公共財產有價值..我不知道如何使它的工作,我一直試着從3天請幫助我。 :(
生病給它一個鏡頭謝謝 –
您的歡迎AymanSalah .. :) –