Search Results

Search found 106 results on 5 pages for 'listboxitem'.

Page 1/5 | 1 2 3 4 5  | Next Page >

  • InvalidCastException from selecting ListBoxItem's Contents

    - by Dan
    My ListBoxItems contain multiple TextBoxes like this: <ListBox Name="myList" SelectionChanged="myList_SelectionChanged"> <ListBox.ItemTemplate> <DataTemplate> <ListBoxItem> <ListBoxItem.Content> <StackPanel Orientation="Vertical"> <TextBlock Name="nameTextBlock" Text="{Binding Name}" /> <TextBlock Name="ageTextBlock" Text="{Binding Age}" /> <TextBlock Name="genderTextBlock" Text="{Binding Gender}" /> <TextBlock Name="heightTextBlock" Text="{Binding Height}" /> </StackPanel> </ListBoxItem.Content> </ListBoxItem> </DataTemplate> </ListBox.ItemTemplate> </ListBox> When an item is clicked, I would like each TextBlock to be saved to IsolatedStorage under corresponding keys. Right now the closest I've gotten to this method is this: private void mysList_SelectionChanged(object sender, SelectionChangedEventArgs e) { ListBoxItem lbi = (ListBoxItem)myList.SelectedItem; appSettings["name"] = (string)lbi.Content; } But, when clicked I get an InvalidCastException. As I understand it, it's basically due to me trying to convert all four textboxes into a single string (or something like that). So how do I save each TextBox's text field independently within the ListBoxItem to an IsolatedStorage key/value? Thanks again in advance.

    Read the article

  • WPF - How do I get an object that is bound to a ListBoxItem back

    - by JonBlumfeld
    Hi there here is what I would like to do. I get a List of objects from a database and bind this list to a ListBox Control. The ListBoxItems consist of a textbox and a button. Here is what I came up with. Up to this point it works as intended. The object has a number of Properties like ID, Name. If I click on the button in the ListBoxItem the Item should be erased from the ListBox and also from the database... <ListBox x:Name="taglistBox"> <ListBox.ItemContainerStyle> <Style TargetType="{x:Type ListBoxItem}"> <Setter Property="HorizontalAlignment" Value="Stretch"/> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="ListBoxItem"> <ContentPresenter HorizontalAlignment="Stretch"/> </ControlTemplate> </Setter.Value> </Setter> <Setter Property="Tag" Value="{Binding TagSelf}"></Setter> </Style> </ListBox.ItemContainerStyle> <ListBox.ItemTemplate> <DataTemplate> <Grid HorizontalAlignment="Stretch"> <Grid.ColumnDefinitions> <ColumnDefinition Width="Auto"/> <ColumnDefinition/> </Grid.ColumnDefinitions> <Button Grid.Column="0" Name="btTag" VerticalAlignment="Center" Click="btTag_Click" HorizontalAlignment="Left"> <Image Width="16" Height="16" Source="/WpfApplication1;component/Resources/104.png"/> </Button> <TextBlock Name="tbtagBoxTagItem" Margin="5" Grid.Column="1" Text="{Binding Name}" VerticalAlignment="Center" /> </Grid> </DataTemplate> </ListBox.ItemTemplate> </ListBox> The Textblock.Text is bound to object.Name and the ListBoxItem.Tag to object.TagSelf (which is just a copy of the object itself). Now my questions If I click the button in the listboxItem how do I get the listboxitem and the object bound to it back. In order to delete the object from the database I have to retrieve it somehow. I tried something like ListBoxItem lbi1 = (ListBoxItem)(taglistBox.ItemContainerGenerator.ContainerFromItem(taglistBox.Items.CurrentItem)); ObjectInQuestion t = (ObjectInQuestion) lbi1.Tag; Is there a way to automatically update the contents of the ListBox if the Itemssource changes? Right now I'm achieving that by taglistBox.ItemsSource = null; taglistBox.ItemsSource = ObjectInQuestion; I'd appreciate any help you can give :D Thanks in advance

    Read the article

  • Mouse interaction in ListBoxItem children (WPF)

    - by absence
    I have a ListBox with an ItemTemplate that contains a control that interacts with the mouse. This interfers with the selection functionality of the ListBox, i.e. clicking a control does not select the item. This is because ListBoxItem sets the Handled property of the mouse event to true in OnMouseLeftButtonDown. I tried the following protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e) { base.OnMouseLeftButtonDown(e); e.Handled = false; } but the ListBoxItem “takes over” the mouse and prevents the control from doing its own interaction. Then I had another idea protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e) { base.OnMouseLeftButtonDown(e); ((ListBoxItem)VisualTreeHelper.GetParent(VisualTreeHelper.GetParent(VisualTreeHelper.GetParent(this)))).IsSelected = true; } which actually works, but feels more like an ugly kludge than an elegant solution. Are there any better solutions that don't rely on the exact contents of the visual tree?

    Read the article

  • Set ListBoxItem.IsSelected when child TextBox is Focused

    - by jpsstavares
    Hi, I have a typical MVVM scenario: I have a ListBox that is binded to a List of StepsViewModels. I define a DataTemplate so that StepViewModels are rendered as StepViews. The StepView UserControl have a set of labels and TextBoxs. What I want to do is to select the ListBoxItem that is wrapping the StepView when a textBox is focused. I've tried to create a style for my TextBoxs with the following trigger: <Trigger Property="IsFocused" Value="true"> <Setter TargetName="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type ListBoxItem}}}" Property="IsSelected" Value="True"/> </Trigger> But I get an error telling me that TextBoxs don't have an IsSelected property. I now that but the Target is a ListBoxItem. How can I make it work?

    Read the article

  • WPF wrappanel item alignment problem when scrolling

    - by Jayho
    Someone help me out pls. I set a wrapPanel in a listbox itemPanelTemplate, Also, I already set the ScrollViewer.CanContentScroll="True". But why the listbox items are not scrolling up/down by ITEM one by one? The scroll style is still by PIXEL. Is anyone help me? <Grid> <ListBox x:Name="testListbox" ScrollViewer.CanContentScroll="True"> <ListBox.ItemsPanel> <ItemsPanelTemplate> <WrapPanel Width="200" ScrollViewer.CanContentScroll="True"/> </ItemsPanelTemplate> </ListBox.ItemsPanel> <ListBoxItem Background="LimeGreen" BorderBrush="Black" BorderThickness="3" ScrollViewer.CanContentScroll="True"> <Image Height="50" Width="80" ScrollViewer.CanContentScroll="True"/> </ListBoxItem> <ListBoxItem Background="LimeGreen" BorderBrush="Black" BorderThickness="3" ScrollViewer.CanContentScroll="True"> <Image Height="50" Width="80" ScrollViewer.CanContentScroll="True"/> </ListBoxItem> <ListBoxItem Background="LimeGreen" BorderBrush="Black" BorderThickness="3" ScrollViewer.CanContentScroll="True"> <Image Height="50" Width="80" ScrollViewer.CanContentScroll="True"/> </ListBoxItem> <ListBoxItem Background="LimeGreen" BorderBrush="Black" BorderThickness="3" ScrollViewer.CanContentScroll="True"> <Image Height="50" Width="80" ScrollViewer.CanContentScroll="True"/> </ListBoxItem> <ListBoxItem Background="LimeGreen" BorderBrush="Black" BorderThickness="3" ScrollViewer.CanContentScroll="True"> <Image Height="50" Width="80" ScrollViewer.CanContentScroll="True"/> </ListBoxItem> <ListBoxItem Background="LimeGreen" BorderBrush="Black" BorderThickness="3" ScrollViewer.CanContentScroll="True"> <Image Height="50" Width="80" ScrollViewer.CanContentScroll="True"/> </ListBoxItem> <ListBoxItem Background="LimeGreen" BorderBrush="Black" BorderThickness="3" ScrollViewer.CanContentScroll="True"> <Image Height="50" Width="80" ScrollViewer.CanContentScroll="True"/> </ListBoxItem> <ListBoxItem Background="LimeGreen" BorderBrush="Black" BorderThickness="3" ScrollViewer.CanContentScroll="True"> <Image Height="50" Width="80" ScrollViewer.CanContentScroll="True"/> </ListBoxItem> <ListBoxItem Background="LimeGreen" BorderBrush="Black" BorderThickness="3" ScrollViewer.CanContentScroll="True"> <Image Height="50" Width="80" ScrollViewer.CanContentScroll="True"/> </ListBoxItem> <ListBoxItem Background="LimeGreen" BorderBrush="Black" BorderThickness="3" ScrollViewer.CanContentScroll="True"> <Image Height="50" Width="80" ScrollViewer.CanContentScroll="True"/> </ListBoxItem> <ListBoxItem Background="LimeGreen" BorderBrush="Black" BorderThickness="3" ScrollViewer.CanContentScroll="True"> <Image Height="50" Width="80" ScrollViewer.CanContentScroll="True"/> </ListBoxItem> <ListBoxItem Background="LimeGreen" BorderBrush="Black" BorderThickness="3" ScrollViewer.CanContentScroll="True"> <Image Height="50" Width="80" ScrollViewer.CanContentScroll="True"/> </ListBoxItem> <ListBoxItem Background="LimeGreen" BorderBrush="Black" BorderThickness="3" ScrollViewer.CanContentScroll="True"> <Image Height="50" Width="80" ScrollViewer.CanContentScroll="True"/> </ListBoxItem> <ListBoxItem Background="LimeGreen" BorderBrush="Black" BorderThickness="3" ScrollViewer.CanContentScroll="True"> <Image Height="50" Width="80" ScrollViewer.CanContentScroll="True"/> </ListBoxItem> <ListBoxItem Background="LimeGreen" BorderBrush="Black" BorderThickness="3" ScrollViewer.CanContentScroll="True"> <Image Height="50" Width="80" ScrollViewer.CanContentScroll="True"/> </ListBoxItem> <ListBoxItem Background="LimeGreen" BorderBrush="Black" BorderThickness="3" ScrollViewer.CanContentScroll="True"> <Image Height="50" Width="80" ScrollViewer.CanContentScroll="True"/> </ListBoxItem> </ListBox> </Grid>

    Read the article

  • How to change the border on a listboxitem while using a predefined template

    - by djerry
    Hey, I'm using one of the defined wpf themes for my application, so all my controls automatically are pimped according to that theme. Now i am filling a listbox with items (usercontrols), but not all of them should be visible at all time. But when i'm setting height to 0 (of usercontrol) or setting to invisible, i get a thick grey border of the listboxitems. Can someone help me override the border of the listboxitem or show me where in the template i need to change the border, cause i just can't find it. This is the part of the template for the listboxitem: <Style d:IsControlPart="True" TargetType="{x:Type ListBoxItem}"> <Setter Property="SnapsToDevicePixels" Value="true"/> <Setter Property="OverridesDefaultStyle" Value="false"/> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type ListBoxItem}"> <ControlTemplate.Resources> <Storyboard x:Key="HoverOn"> <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="HoverRectangle" Storyboard.TargetProperty="(UIElement.Opacity)"> <SplineDoubleKeyFrame KeyTime="00:00:00.2000000" Value="1"/> </DoubleAnimationUsingKeyFrames> </Storyboard> <Storyboard x:Key="HoverOff"> <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="HoverRectangle" Storyboard.TargetProperty="(UIElement.Opacity)"> <SplineDoubleKeyFrame KeyTime="00:00:00.3000000" Value="0" /> </DoubleAnimationUsingKeyFrames> </Storyboard> <Storyboard x:Key="SelectedOn"> <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="SelectedRectangle" Storyboard.TargetProperty="(UIElement.Opacity)"> <SplineDoubleKeyFrame KeyTime="00:00:00.2000000" Value="1"/> </DoubleAnimationUsingKeyFrames> </Storyboard> <Storyboard x:Key="SelectedOff"> <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="SelectedRectangle" Storyboard.TargetProperty="(UIElement.Opacity)"> <SplineDoubleKeyFrame KeyTime="00:00:00.3000000" Value="0" /> </DoubleAnimationUsingKeyFrames> </Storyboard> </ControlTemplate.Resources> <Grid Background="{TemplateBinding Background}" Margin="1,1,1,1" SnapsToDevicePixels="true" x:Name="grid"> <Rectangle x:Name="Background" IsHitTestVisible="False" Fill="{StaticResource SelectedBackgroundBrush}" RadiusX="0"/> <Rectangle x:Name="SelectedRectangle" IsHitTestVisible="False" Opacity="0" Fill="{StaticResource NormalBrush}" RadiusX="0"/> <Rectangle x:Name="HoverRectangle" IsHitTestVisible="False" Fill="{StaticResource HoverBrush}" RadiusX="0" Opacity="0"/> <ContentPresenter Margin="5,3,3,3" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" x:Name="contentPresenter"/> </Grid> <ControlTemplate.Triggers> <Trigger Property="IsMouseOver" Value="true"> <Trigger.EnterActions> <BeginStoryboard Storyboard="{StaticResource HoverOn}"/> </Trigger.EnterActions> <Trigger.ExitActions> <BeginStoryboard Storyboard="{StaticResource HoverOff}"/> </Trigger.ExitActions> </Trigger> <Trigger Property="IsSelected" Value="true"> <Trigger.EnterActions> <BeginStoryboard Storyboard="{StaticResource SelectedOn}"/> </Trigger.EnterActions> <Trigger.ExitActions> <BeginStoryboard Storyboard="{StaticResource SelectedOff}"/> </Trigger.ExitActions> </Trigger> <Trigger Property="IsEnabled" Value="false"> <Setter Property="Foreground" Value="{DynamicResource DisabledForegroundBrush}"/> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> </Setter> <Setter Property="Foreground" Value="{DynamicResource TextBrush}"/> </Style>

    Read the article

  • ListBoxItem.Parent returns nothing, unable to get it thru VisualTreeHelper.GetParent either

    - by Shimmy
    How do I extract the parent container of a ListBoxItem? In the following example I can go till the ListBoxItem, higher than that I get Nothing: <ListBox Name="lbAddress"> <ListBox.ItemTemplate> <DataTemplate> <Button Click="Button_Click"/> </DataTemplate> </ListBox.ItemTemplate> </ListBox> Private Sub Button_Click(sender As Button, e As RoutedEventArgs) Dim lbAddress = GetAncestor(Of ListBox) 'Result: Nothing End Sub Public Shared Function GetAncestor(Of T)(reference As DependencyObject) As T Dim parent = GetParent(reference) While parent IsNot Nothing AndAlso Not parent.GetType.Equals(GetType(T)) parent = GetAncestor(Of T)(parent) End While If parent IsNot Nothing Then _ Return If(parent.GetType Is GetType(T), parent, Nothing) Return Nothing End Sub Public Function GetParent(reference As DependencyObject) As DependencyObject Dim parent As DependencyObject = Nothing If TypeOf reference Is FrameworkElement Then parent = DirectCast(reference, FrameworkElement).Parent ElseIf TypeOf reference Is FrameworkContentElement Then parent = DirectCast(reference, FrameworkContentElement).Parent End If Return If(parent, VisualTreeHelper.GetParent(reference)) End Function Update This is what happens (note that the 'parent' variable remains null):

    Read the article

  • ListBoxItem IsSelected style

    - by plotnick
    I still didn't get it. Could you please show me exactly how to override ListBox's default behavior. Everytime when ListBoxItem is selected the Border's background should be changed. Not the background of the whole row but only background of the border which's specified. <ListBox ItemsSource="{Binding Source={StaticResource AssetsViewSource}}"> <ListBox.ItemTemplate> <DataTemplate> <Border BorderThickness="2" BorderBrush="Black"> <StackPanel> <TextBlock Text="Name: " /> <TextBlock Text="{Binding Name}" /> </StackPanel> </Border> </DataTemplate> </ListBox.ItemTemplate> </ListBox>

    Read the article

  • ListBoxItem height not getting updated

    - by Gili
    Hi, I have a listbox inside another list box, in inner list box listboxitems height may grow or shrink. My problem is that when the inner items shrink the outer list box doesn't re-render its height. Thus - stays with the previous height before the inner list shrinked. I have tried so many things here, among Invalidate of all types, selection and de-selection of the list box item that should be updated and more - nothing helps.... Can anyone pls help me with this? Thanx, Gili

    Read the article

  • WPF - ListBox ignores Style When ItemsSource is bound

    - by Andy T
    Hi, I have created styled a ListBox in WPF so that it is rendered as a checkbox list. When I populate the ListBox's items manually, the styling works perfectly. However, when I instead bind the ItemsSource of the ListBox to a static resource (an ItemsControl containing the required items), the styling is completely dropped. Here's the style: <Style x:Key="CheckBoxListStyle" TargetType="ListBox"> <Style.Resources> <Style TargetType="ListBoxItem"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="ListBoxItem"> <Grid Margin="2"> <Grid.ColumnDefinitions> <ColumnDefinition Width="Auto" /> <ColumnDefinition /> </Grid.ColumnDefinitions> <CheckBox IsChecked="{Binding IsSelected, RelativeSource={RelativeSource TemplatedParent}, Mode=TwoWay}"/> <ContentPresenter Grid.Column="1" Margin="2,0,0,0" /> </Grid> </ControlTemplate> </Setter.Value> </Setter> </Style> </Style.Resources> <Setter Property="ItemsPanel"> <Setter.Value> <ItemsPanelTemplate> <WrapPanel Orientation="Vertical" /> </ItemsPanelTemplate> </Setter.Value> </Setter> <Setter Property="BorderThickness" Value="0" /> <Setter Property="Background" Value="Transparent" /> </Style> Here's the code for the ListBox that shows the style correctly: <ListBox x:Name="ColumnsList" Grid.Column="0" Grid.Row="0" Style="{StaticResource CheckBoxListStyle}" BorderThickness="1"> <ListBox.Items> <ListBoxItem>Test</ListBoxItem> <ListBoxItem>Test2</ListBoxItem> <ListBoxItem>Test3</ListBoxItem> </ListBox.Items> </ListBox> Here's the code for the ListBox that ignores the style: <ListBox x:Name="ColumnsList2" Grid.Column="0" Grid.Row="0" Style="{StaticResource CheckBoxListStyle}" BorderThickness="1" ItemsSource="{Binding Source={StaticResource Test1}, Path=Items}"> </ListBox> Hoping someone can help - I'm pretty new to all this and have tried everything I can think of, but everything I've read leads me to believe that setting ItemsSource should have the same outcome as setting the items manually, so I can't see any reason why this would not work. Thanks, AT

    Read the article

  • WPF XAML: How to trigger style change in ListBoxItem ancestor to user class?

    - by dhovel
    I have an ObservableCollection of items of my class "PlaylistItem" that implements INotifyPropertyChanged. The collection is databound to a ListBox and everything else is working. I want to know what markup to use to trigger a style change of the wrapping ListBoxItem based on a property (e.g. "Playing", bool) of the PlaylistItem. How to I use FindAncestor to trigger the change? I can to this in code, but I know I that I can (somehow) do it in markup. Thanks in advance.

    Read the article

  • Can you set a gradient brush for a listboxitem background in silverlight?

    - by Michael
    I am looking for a way to set a gradientbrush as the background for a listbox item. I have a DataTemplate defined and have specified a gradient brush but it always appears as the listbox background (i.e. it never shows as a gradient brush). I have been able to set the background of the listbox itself, and I can set the listboxitem's background to a standard color using the "setter" object....but none of these are what I am after. I really want the background on each list item to be a gradient brush. Below is the datatemplate that I have constructed. <ListBox Name="MyListBox" Margin="12,67,12,169"> <ListBox.ItemTemplate> <DataTemplate> <Grid Height="51" VerticalAlignment="Bottom"> <Grid.Background> <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0"> <GradientStop Color="#FFC9F4D0"/> <GradientStop Color="#FF2AC12A" Offset="0.333"/> <GradientStop Color="#FF35DE35" Offset="1"/> </LinearGradientBrush> </Grid.Background> <Canvas > <dataInput:Label Width="227" Foreground="Yellow" Canvas.Left="158" Canvas.Top="8" Content="{Binding Place}"/> <dataInput:Label Width="146" Foreground="Yellow" Canvas.Left="8" Canvas.Top="8" Content="{Binding Date}"/> <dataInput:Label Content="{Binding People}" Width="346" FontSize="9.333" Foreground="Black" Canvas.Left="166" Canvas.Top="28"/> <!-- <dataInput:Label Width="45" Content="Accept" Foreground="White" Canvas.Left="8" Canvas.Top="28"/> <dataInput:Label Width="45" Content="Decline" Foreground="White" Canvas.Left="57" Canvas.Top="28"/> --> <dataInput:Label Content="SomeText" Width="101" FontSize="9.333" Foreground="White" Canvas.Left="389" Canvas.Top="10"/> <Image Height="21" Width="21" Canvas.Left="500" Canvas.Top="8" Source="Green Button.png"/> </Canvas> </Grid> </DataTemplate> </ListBox.ItemTemplate> </ListBox> Any Thoughts?

    Read the article

  • Setting properties of auto-generated listboxitem

    - by DerKlaus
    I am trying to set the inputbindings of the auto-generated ListBoxItems of a databound ListBox. The code below does not work. The compiler complains that "The Property Setter 'InputBindings' cannot be set because it does not have an accessible set accessor." What is the correct syntax to set the InputBindings? <ListBox.ItemContainerStyle> <Style TargetType="{x:Type ListBoxItem}"> <Setter Property="ListBoxItem.InputBindings"> <Setter.Value> <MouseBinding Command="{Binding OpenCommand}" Gesture="LeftDoubleClick"/> </Setter.Value> </Setter> </Style> </ListBox.ItemContainerStyle> PS: Posting does not work with Opera 10.51

    Read the article

  • How to use IsKeyboardFocusWithin and IsSelected together?

    - by jpsstavares
    I have a style defined for my ListBoxItems with a trigger to set a background color when IsSelected is True: <Style x:Key="StepItemStyle" TargetType="{x:Type ListBoxItem}"> <Setter Property="SnapsToDevicePixels" Value="true"/> <Setter Property="OverridesDefaultStyle" Value="true"/> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="ListBoxItem"> <Border Name="Border" Padding="0" SnapsToDevicePixels="true"> <ContentPresenter /> </Border> <ControlTemplate.Triggers> <Trigger Property="IsSelected" Value="True"> <Setter TargetName="Border" Property="Background" Value="#40a0f5ff"/> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> </Setter> </Style> This style maintains the selected item even when the ListBox and ListBoxItem loses focus, which in my case is an absolute must. The problem is that I also want the ListBoxItem to be selected when one of its TextBox's child gets focused. To achieve this I add a trigger that sets IsSelected to true when IsKeyboardFocusWithin is true: <Trigger Property="IsKeyboardFocusWithin" Value="True"> <Setter Property="IsSelected" Value="True" /> </Trigger> When I add this trigger the Item is selected when the focus is on a child TextBox, but the first behaviour disappears. Now when I click outside the ListBox, the item is de-selected. How can I keep both behaviours?

    Read the article

  • UserControl as ListBoxItem and IsSelected

    - by mattjf
    I have a usercontrol that I want to use as a ListBoxItem. <ListBox.ItemTemplate> <DataTemplate> <local:MyUserControl/> </DataTemplate> </ListBox.ItemTemplate> I'd like to play a storyboard when the usercontrol is unselected. <UserControl.Resources> <Style TargetType="{x:Type UserControl}"> <Style.Triggers> <DataTrigger Binding="{Binding IsSelected, RelativeSource={RelativeSource AncestorType={x:Type ListBoxItem}, Mode=FindAncestor}}" Value="False"> <DataTrigger.EnterActions> <BeginStoryboard Storyboard="{StaticResource OnMouseLeaveSB}"/> </DataTrigger.EnterActions> </DataTrigger> </Style.Triggers> </Style> </UserControl.Resources> But the storyboard is never firing. Is there a better way to do this? Edited to Add: What I am really trying to accomplish this this: When the mouse is over the UserControl, I want to play a storyboard (OnMouseEnterSB). When the mouse leaves the UserControl, I want to play another storyboard (OnMouseLeaveSB). I have all this working fine. When the UserControl is selected, however, and the mouse leaves, I do NOT want to play the storyboard. Finally, when the UserControl is unselected, I want to play the OnMouseLeaveSB storyboard.

    Read the article

  • Silverlight MVVM ListBoxItem IsSelected

    - by Lee
    I have a collection of ViewModels bound to a ListBox. I am trying to bind the IsSelected properties of each together. In WPF it works by setting the style: <Style TargetType="{x:Type ListBoxItem}"> <Setter Property="IsSelected" Value="{Binding Path=IsSelected, Mode=TwoWay}" /> </Style> This does not work in Silverlight. How can I accomplish this?

    Read the article

  • Prevent ListBox from focusing but leave ListBoxItem(s) focusable (wpf)

    - by modosansreves
    Here is what happens: I have a listbox with items. Listbox has focus. Some item (say, 5th) is selected (has a blue background), but has no 'border'. When I press 'Down' key, the focus moves from ListBox to the first ListBoxItem. (What I want is to make 6th item selected, regardless of the 'border') When I navigate using 'Tab', the Listbox never receives the focus again. But when the collection is emptied and filled again, ListBox itself gets focus, pressing 'Down' moves the focus to the item. How to prevent ListBox from gaining focus? P.S. listBox1.SelectedItem is my own class, I don't know how to make ListBoxItem out of it to .Focus() it. EDIT: the code Xaml: <UserControl.Resources> <me:BooleanToVisibilityConverter x:Key="visibilityConverter"/> <me:BooleanToItalicsConverter x:Key="italicsConverter"/> </UserControl.Resources> <ListBox x:Name="lbItems"> <ListBox.ItemTemplate> <DataTemplate> <Grid> <ProgressBar HorizontalAlignment="Stretch" VerticalAlignment="Bottom" Visibility="{Binding Path=ShowProgress, Converter={StaticResource visibilityConverter}}" Maximum="1" Margin="4,0,0,0" Value="{Binding Progress}" /> <TextBlock Text="{Binding Path=VisualName}" FontStyle="{Binding Path=IsFinished, Converter={StaticResource italicsConverter}}" Margin="4" /> </Grid> </DataTemplate> </ListBox.ItemTemplate> <me:OuterItem Name="Regular Folder" IsFinished="True" Exists="True" IsFolder="True"/> <me:OuterItem Name="Regular Item" IsFinished="True" Exists="True"/> <me:OuterItem Name="Yet to be created" IsFinished="False" Exists="False"/> <me:OuterItem Name="Just created" IsFinished="False" Exists="True"/> <me:OuterItem Name="In progress" IsFinished="False" Exists="True" Progress="0.7"/> </ListBox> where OuterItem is: public class OuterItem : IOuterItem { public Guid Id { get; set; } public string Name { get; set; } public bool IsFolder { get; set; } public bool IsFinished { get; set; } public bool Exists { get; set; } public double Progress { get; set; } /// Code below is of lesser importance, but anyway /// #region Visualization helper properties public bool ShowProgress { get { return !IsFinished && Exists; } } public string VisualName { get { return IsFolder ? "[ " + Name + " ]" : Name; } } #endregion public override string ToString() { if (IsFinished) return Name; if (!Exists) return " ??? " + Name; return Progress.ToString("0.000 ") + Name; } public static OuterItem Get(IOuterItem item) { return new OuterItem() { Id = item.Id, Name = item.Name, IsFolder = item.IsFolder, IsFinished = item.IsFinished, Exists = item.Exists, Progress = item.Progress }; } } ?onverters are: /// Are of lesser importance too (for understanding), but will be useful if you copy-paste to get it working public class BooleanToItalicsConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { bool normal = (bool)value; return normal ? FontStyles.Normal : FontStyles.Italic; } public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { throw new NotImplementedException(); } } public class BooleanToVisibilityConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { bool exists = (bool)value; return exists ? Visibility.Visible : Visibility.Collapsed; } public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { throw new NotImplementedException(); } } But most important, is that UserControl.Loaded() has: lbItems.Items.Clear(); lbItems.ItemsSource = fsItems; where fsItems is ObservableCollection<OuterItem>. The usability problem I describe takes place when I Clear() that collection (fsItems) and fill with new items.

    Read the article

  • Binding the property to a control defined inside a listboxitem template

    - by Malcolm
    I have a class called ledgerObject : public class LedgerObject { public ChargeLine ChargeLine{ get; set; } public DelegateCommand Click_hyperbnCommand{ get; private set; } public LedgerObject() { this.Click_hyperbnCommand = new DelegateCommand(click_btn); } private void click_btn(object args) { } } The chargeLine which is the property of this class is itself a class and has some properties in it. So I am binding the datacontext of a listbox to an array of LedgerObject, and I want to bind the textblock control defined inside a listboxitem template to the property of a ChargeLine. Any idea or suggestion will help. I have tried this but not working: <TextBlock Margin="4 0 4 0" Grid.Column="3" Text="{Binding Path=ChargeLine.SimCode}" TextDecorations="Underline" Foreground="Red" />

    Read the article

  • How not to include a Thumb in ListBoxItem selection

    - by Elad
    I have a collection of items. I am presenting the items in a WPF ListBox using DataTemplate. Part of the DataTemplate is a Thumb which is used for resizing and visually separating between items. The Thumb.Visibility is binded to a property of the item (for example, the last item doesn’t have a visible Thumb). The problem is that selecting an item in the ListBox selects the Thumb as well, as it is part of the ListBoxItem. The desired behavior is to select only the data without the Thumb. How is it possible to get this behavior? I don’t want to add items by code the ListBox or to handle the visibility of the Thumb manually. Currently I get all this from the DataTemplate.

    Read the article

  • How to have a user control as a ListBoxItem

    - by Harry
    I want to bind a user control (View) to a ListBoxItem. The ListBox is bound to a collection of ViewModels. I have set the ListBox's ItemTemplate as so: <ListBox.ItemTemplate> <DataTemplate> <View:ContactView/> </DataTemplate> </ListBox.ItemTemplate> But all I get are blank ListBoxItems. I can click on them, but nothing is showing visually. My ContactView code is very simply: <Border> <DockPanel> <StackPanel DockPanel.Dock="Right" Orientation="Vertical"> <TextBlock Text="{Binding Path=ContactFirstName, FallbackValue=FirstName}" FontWeight="Bold" Margin="5, 0, 5, 0"></TextBlock> <TextBlock Text="{Binding Path=ContactLastName, FallbackValue=LastName}" FontWeight="Bold" Margin="5, 0, 5, 0"></TextBlock> <TextBlock Text="{Binding Path=ContactNumber, FallbackValue=Number}" Margin="5, 0, 5, 0"></TextBlock> </StackPanel> </DockPanel> </Border> What could be wrong with this? Thanks.

    Read the article

  • Find ListBox from its child?

    - by Shimmy
    How do I extract the parent container of a ListBoxItem? In the following example I can go till the ListBoxItem, higher than that I get Nothing: <ListBox Name="lbAddress"> <ListBox.ItemTemplate> <DataTemplate> <Button Click="Button_Click"/> </DataTemplate> </ListBox.ItemTemplate> </ListBox> Private Sub Button_Click(sender As Button, e As RoutedEventArgs) Dim lbAddress = GetAncestor(Of ListBox) 'Result: Nothing End Sub Public Shared Function GetAncestor(Of T)(reference As DependencyObject) As T Dim parent = GetParent(reference) While parent IsNot Nothing AndAlso Not parent.GetType.Equals(GetType(T)) parent = GetVisualAncestor(Of T)(parent) End While If parent IsNot Nothing Then _ Return If(parent.GetType Is GetType(T), parent, Nothing) Return Nothing End Sub Public Function GetParent(reference As DependencyObject) As DependencyObject Dim parent As DependencyObject = Nothing If TypeOf reference Is FrameworkElement Then parent = DirectCast(reference, FrameworkElement).Parent ElseIf TypeOf reference Is FrameworkContentElement Then parent = DirectCast(reference, FrameworkContentElement).Parent End If Return If(parent, VisualTreeHelper.GetParent(reference)) End Function

    Read the article

1 2 3 4 5  | Next Page >