如何为每张图片设置文字来源?我想要为每个图像添加特定的描述,但是现在我对所有图像都有相同的文本。我正在考虑创建一个文件夹,在其中制作10个.txt文件并设置每个图像以使其中一个文件作为描述..但我只知道如何理论上这样做。这是我正在谈论的指令和按钮。
var files = Directory.GetFiles(@".\GalleryImages");
foreach (var file in files)
{
FileInfo fileInfo = new FileInfo(file);
WineModel wineModel = new WineModel();
wineModel.Image = new Uri(file, UriKind.Relative);
wineModel.Description = file + "text text text text text text text text text text text" +
Environment.NewLine + "text text text text text text text text text text text";
wineModel.Price = new Random().NextDouble();
BitmapImage bi = new BitmapImage();
bi.BeginInit();
bi.UriSource = wineModel.Image;
bi.EndInit();
var button = new KinectTileButton
{
Label = System.IO.Path.GetFileNameWithoutExtension(file),
Background = new ImageBrush(bi),
Tag = wineModel
};
this.wrapPanel.Children.Add(button);
}
这是按钮
private void KinectTileButtonClick(object sender, RoutedEventArgs e)
{
var button = (KinectTileButton)e.Source;
var wineModel = button.Tag as WineModel;
var selectionDisplay = new SelectionDisplay(wineModel);
this.kinectRegionGrid.Children.Add(selectionDisplay);
e.Handled = true;
}
编辑:这是xaml代码..你能给我更多细节Stefan吗?我真的不明白你想说什么
<UserControl x:Class="Microsoft.Samples.Kinect.ControlsBasics.SelectionDisplay"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:k="http://schemas.microsoft.com/kinect/2013"
mc:Ignorable="d"
d:DesignHeight="300"
d:DesignWidth="300"
Background="Transparent"
FontFamily="Segoe UI"
FontSize="30">
<!--<Grid x:Name="layoutRoot">-->
<Grid x:Name="grid" Background="{StaticResource BlueBrush}" Width="auto">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Image Grid.Row="0" Grid.Column="0" Grid.RowSpan="3" x:Name="Display" HorizontalAlignment="Left"
VerticalAlignment="Center" Height="185" Width="293" Margin="50,0,10,0" />
<TextBlock Grid.Row="0" Grid.Column="1" Grid.RowSpan="2" x:Name="Description" HorizontalAlignment="Left"
TextWrapping="Wrap" Text="" VerticalAlignment="Top" MaxHeight="400" MaxWidth="500"
Margin="0,20,0,0"/>
<TextBlock Grid.Row="2" Grid.Column="1" x:Name="Price" HorizontalAlignment="Left"
TextWrapping="Wrap" Text="" VerticalAlignment="Top" Height="85" Width="294"/>
<Viewbox Grid.Row="0" Grid.Column="3" MaxHeight="720" MaxWidth="1280" Margin="60 60 60 60">
<Canvas Width="1280" Height="720">
<k:KinectCircleButton Style="{StaticResource CancelButtonStyle}" Canvas.Right="-153" Canvas.Top="-153"
Foreground="White" Height="200" Width="200" Click="OnCloseFullImage" />
</Canvas>
</Viewbox>
</Grid>
<!--</Grid>-->
编辑:这是xaml代码
<UserControl x:Class="Microsoft.Samples.Kinect.ControlsBasics.SelectionDisplay"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:k="http://schemas.microsoft.com/kinect/2013"
mc:Ignorable="d"
d:DesignHeight="300"
d:DesignWidth="300"
Background="Transparent"
FontFamily="Segoe UI"
FontSize="30">
<!--<Grid x:Name="layoutRoot">-->
<Grid x:Name="grid" Background="{StaticResource BlueBrush}" Width="auto">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Image Grid.Row="0" Grid.Column="0" Grid.RowSpan="3" x:Name="Display" HorizontalAlignment="Left"
VerticalAlignment="Center" Height="185" Width="293" Margin="50,0,10,0" />
<TextBlock Grid.Row="0" Grid.Column="1" Grid.RowSpan="2" x:Name="Description" HorizontalAlignment="Left"
TextWrapping="Wrap" Text="" VerticalAlignment="Top" MaxHeight="400" MaxWidth="500"
Margin="0,20,0,0"/>
<TextBlock Grid.Row="2" Grid.Column="1" x:Name="Price" HorizontalAlignment="Left"
TextWrapping="Wrap" Text="" VerticalAlignment="Top" Height="85" Width="294"/>
<Viewbox Grid.Row="0" Grid.Column="3" MaxHeight="720" MaxWidth="1280" Margin="60 60 60 60">
<Canvas Width="1280" Height="720">
<k:KinectCircleButton Style="{StaticResource CancelButtonStyle}" Canvas.Right="-153" Canvas.Top="-153"
Foreground="White" Height="200" Width="200" Click="OnCloseFullImage" />
</Canvas>
</Viewbox>
</Grid>
<!--</Grid>-->