14 March 2014

Change Background Image on pressed ListBox

<Grid x:Name="LayoutRoot" Background="Transparent">
        <!--toolkit:TiltEffect.IsTiltEnabled="True"-->
        <ListBox x:Name="Channel_List" SelectionChanged="Listbox1_SelectionChanged" >
         
            <ListBox.ItemTemplate>
                <DataTemplate>
                 
                    <ListBoxItem >
                        <StackPanel Width="490" MouseLeave="StackPanel_MouseLeave"  MouseLeftButtonDown="StackPanel_MouseLeftButtonDown" MouseLeftButtonUp="StackPanel_MouseLeftButtonUp">
                            <StackPanel.Background>
                                <ImageBrush ImageSource="/Assets/Images/channel-bg-unsel.png"/>
                            </StackPanel.Background>
                            <Image Source="{Binding Image}" />
                            <TextBlock Text="{Binding StationName}" FontFamily="Segoe Print" />
                        </StackPanel>
                    </ListBoxItem>
                 
                </DataTemplate>
            </ListBox.ItemTemplate>
         
        </ListBox>

     
     
    </Grid>


/////handle click events in code behind..



private void StackPanel_MouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {
            var obj = (sender as StackPanel);
            ImageSource img = new BitmapImage(new Uri("/Assets/Images/channel-bg-sel.png", UriKind.Relative));
           ImageBrush ig = new ImageBrush();
           ig.ImageSource = img;
           obj.Background = ig;
            //obj.Background =
        }

        private void StackPanel_MouseLeftButtonUp(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {
            var obj = (sender as StackPanel);
            ImageSource img = new BitmapImage(new Uri("/Assets/Images/channel-bg-unsel.png", UriKind.Relative));
            ImageBrush ig = new ImageBrush();
            ig.ImageSource = img;
            obj.Background = ig;
        }

        private void StackPanel_MouseLeave(object sender, System.Windows.Input.MouseEventArgs e)
        {
            var obj = (sender as StackPanel);
            ImageSource img = new BitmapImage(new Uri("/Assets/Images/channel-bg-unsel.png", UriKind.Relative));
            ImageBrush ig = new ImageBrush();
            ig.ImageSource = img;
            obj.Background = ig;
        }









selectedSelected-background-image

unselectedSelected-background-image

Contact Form

Name

Email *

Message *

Smooth Graphics Java

// Arrange Bricks in Game //java brick breaker game code without flickering // added game levels 1,2,3 in the game //java paddle ball ga...