0

How do I set the text source for each image? I want a specific description for each image, but right now I have the same text for all of them. I was thinking of creating a folder in which to make 10 .txt files and set each image to have one of the files as a description.. but I only know how to do this theoretically. This is the instruction and the button that I'm talking about.

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);
            }

This is the 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;

    }

EDIT:this is the xaml code.. can you give me more details Stefan? I don't really understand what you're trying to say

<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>-->

EDIT:This is xaml code

<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>-->

  • This is wpf? Where is your xaml? – UIlrvnd Apr 11 '14 at 16:24
  • Anyway, if this is indeed wpf, you can have an object that would contain, say the image path and description, xml-serialize that and bind to it(directly or not).. – UIlrvnd Apr 11 '14 at 16:27
  • 1
    possible duplicate of [How to apply a different text for each image?](http://stackoverflow.com/questions/23008378/how-to-apply-a-different-text-for-each-image) – Flat Eric Apr 11 '14 at 16:36
  • Obvious duplicate, it's the same user. – UIlrvnd Apr 11 '14 at 16:46
  • Please don't reask the same question. Edit the original question instead! – BradleyDotNET Apr 11 '14 at 16:50
  • Wouldn't what i suggested work? It's basically an indexing approach, you save that to a db or xml.. i mean, i had a similar project with images and additional data (though not tags) and it worked well.. – UIlrvnd Apr 11 '14 at 16:58
  • maybe your ideea is good, but I don't know where to begin, how to do that, you see? – user3522950 Apr 11 '14 at 17:05
  • Well, you create a class (read up on xm serialization) and make the path and description properties of that class (strings), then you serialize/de-serialize that (or the whole collection) to xml, and bind to the properties from xaml. – UIlrvnd Apr 11 '14 at 17:08
  • can you recommend me some video tutorials about serialization which can show me how to create the path you were talking about? Please follow this topic, I'll keep you posted about my progress and I might need some help – user3522950 Apr 11 '14 at 17:30

0 Answers0