我有两个ListView
绑定到两个不同的属性。基本上这些是两个选择器(一个用于分钟,另一个用于几个小时)。
ItemSource
绑定到静态List<int>
,SelectedValue
绑定到模型中的属性。
当我从小时列表中选择一个值时,它会保持其选定状态...但是当我从分钟列表中选择第二个值时,它会丢失它,反之亦然。
我认为这是一个图形问题,因为即使取消选择一个值,这两个值也会保留。
ListView电话:
<ListView x:Name="listViewHoursSelect" ItemsSource="{Binding MaxHoursList}" SelectedValue="{Binding SelectedMaxHours}" FontSize="{DynamicResource FontText}" Background="{x:Null}" BorderBrush="{x:Null}" Foreground="{DynamicResource MainGray}" Style="{DynamicResource TimeSelectListView}" ItemsPanel="{DynamicResource TimeSelectItemsPanelTemplate}" Margin="0" ItemContainerStyle="{DynamicResource ListViewItemStyle1}" SelectionMode="Single">
<ListView.View>
<GridView>
<GridViewColumn Width="Auto"/>
</GridView>
</ListView.View>
</ListView>
ItemContainerStyle:
<Style x:Key="ListViewItemStyle" TargetType="{x:Type ListViewItem}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ListViewItem}">
<StackPanel x:Name="stackPanel">
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CommonStates">
<VisualStateGroup.Transitions>
<VisualTransition GeneratedDuration="0:0:0.2"/>
</VisualStateGroup.Transitions>
<VisualState x:Name="Normal"/>
<VisualState x:Name="MouseOver">
<Storyboard>
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="textBlock">
<EasingDoubleKeyFrame KeyTime="0" Value="1"/>
</DoubleAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(TextElement.Foreground)" Storyboard.TargetName="textBlock">
<DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource MainRed}"/>
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
<VisualState x:Name="Disabled">
<Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(TextElement.Foreground)" Storyboard.TargetName="textBlock">
<DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource LightGray}"/>
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
<VisualState x:Name="Unselected"/>
<VisualState x:Name="Selected">
<Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(TextElement.Foreground)" Storyboard.TargetName="textBlock">
<DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource MainRed}"/>
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
<VisualState x:Name="Focused">
<Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(TextElement.Foreground)" Storyboard.TargetName="textBlock">
<DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource MainRed}"/>
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
<VisualState x:Name="SelectedUnfocused"/>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<TextBlock x:Name="textBlock" TextWrapping="Wrap" HorizontalAlignment="Center" VerticalAlignment="Center" Text="{Binding DataContext, RelativeSource={RelativeSource TemplatedParent}}" Background="{x:Null}" Foreground="{DynamicResource MainGray}"/>
</StackPanel>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
我重新调整了很多ListView
s,我甚至设置了所有状态(Normal,MouseOver,Selected等等)。我很难找到为什么它保留所选值,直到我在另一个列表中选择另一个值。
如果您需要一些代码,请告诉我,我还没有发布任何内容,因为它很多。
答案 0 :(得分:0)
解决了它,我忘了设置SelectedUnfocused状态:)
<VisualState x:Name="SelectedUnfocused">
<Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(TextElement.Foreground)" Storyboard.TargetName="textBlock">
<DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource MainRed}"/>
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</VisualState>