Click here to Skip to main content
15,885,244 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I want to show the listbox selected item (image) in any other control but in larger size

i have tried with two listboxes andalso by setting IsSynchronizedWithCurrentItem="True" but it is not working, please find the code below.


XML
<Window x:Class="MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="MainWindow" Height="350" Width="525" WindowStartupLocation="CenterScreen" 
    WindowState="Maximized">
    
    <Window.Resources>
        <XmlDataProvider x:Key="myXmlDataBase" XPath="/myXmlData">
            <x:XData>
                <myXmlData xmlns="">
                    <Item Name = "CoverSheet" SNo="1"  Type="GrpBX" Image="C:\Work\00288511851128436163\N12201_0003_003\00000003.tif"/>
                    <Item Name = "HCFA" SNo="2" Type="GrpBX" Image="C:\Work\00288511851128436163\N12201_0003_003\00000004.tif"/>
                    <Item Name = "HCFA" SNo="3" Type="GrpBX" Image="C:\Work\00288511851128436163\N12201_0003_003\00000004.tif"/>
                    <Item Name = "HCFA" SNo="4" Type="GrpBX" Image="C:\Work\00288511851128436163\N12201_0003_003\00000004.tif"/>
                 </myXmlData>
            </x:XData>
        </XmlDataProvider>
    </Window.Resources>

    <DockPanel LastChildFill="True"   DataContext="{Binding Source={StaticResource myXmlDataBase}}">
        
       
            <!--ItemsSource="{Binding Source={StaticResource myXmlDataBase},XPath=Item}"-->
            <ListBox Name="lv"  FontSize="12" removed="LightSteelBlue" ItemsSource="{Binding Source={StaticResource myXmlDataBase},XPath=Item}"      
            ScrollViewer.CanContentScroll="True" ScrollViewer.VerticalScrollBarVisibility="Auto" SelectionMode="Single"    
            DataContext="{Binding}" IsSynchronizedWithCurrentItem="True" DockPanel.Dock="Top" SelectedIndex="0" >
                 <ListBox.ItemsPanel>
                    <ItemsPanelTemplate>
                        <VirtualizingStackPanel  Orientation="Horizontal" HorizontalAlignment="Stretch" removed="White" Width="Auto" Height="Auto" />
                    </ItemsPanelTemplate>
                </ListBox.ItemsPanel>

                <ListBox.ItemTemplate>
                    <!--Source="{Binding XPath=@Image}"-->
                    <DataTemplate>
                        <Viewbox Stretch="None"  HorizontalAlignment="Stretch" >
                            <Border BorderThickness="1" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" DataContext="{Binding}" BorderBrush="IndianRed"   Margin="0" Height="Auto">
                                <DockPanel>
                                    <Image 
                                    DockPanel.Dock="Top" Width="150" Margin="5" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Height="Auto"  
                                    x:Name="Myimage" RenderOptions.BitmapScalingMode="HighQuality"  Source="{Binding XPath=@Image}">
                                    </Image>
                                    <Grid>
                                        <TextBlock Text="{Binding XPath=@SNo}" HorizontalAlignment="Center" FontWeight="Normal"   FontSize="13"  />
                                    </Grid>
                                </DockPanel>
                            </Border>
                        </Viewbox>
                    </DataTemplate>
                </ListBox.ItemTemplate>
            </ListBox>

        <ListBox Name="lv1"  FontSize="12" removed="LightSteelBlue" DataContext="{Binding ElementName=lv, Path=SelectedItems}" ItemsSource="{Binding}"     
            ScrollViewer.CanContentScroll="True" ScrollViewer.VerticalScrollBarVisibility="Auto" SelectionMode="Single" KeyUp="lv1_keyup"  >
           
            <ListBox.ItemsPanel>
                <ItemsPanelTemplate>
                    <DockPanel   LastChildFill="True" HorizontalAlignment="Stretch" removed="LightSteelBlue"  Width="Auto" Height="Auto" />
                </ItemsPanelTemplate>
            </ListBox.ItemsPanel>

            <ListBox.ItemTemplate>
                               <DataTemplate>
                    <Viewbox Stretch="None"  HorizontalAlignment="Stretch"  >
                               <Image 
                                    Width="150" Margin="5" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Height="Auto"  
                                    x:Name="Myimage" RenderOptions.BitmapScalingMode="HighQuality" Source="{Binding}" >
                                </Image>
                    </Viewbox>
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>
      
    </DockPanel>
</Window>

i have tried with XmlDataProvider ,but in real scenario i will get the images through collection. sholud i handle same solution even when get the images from collection
Posted
Updated 27-Jul-13 2:14am
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900