当组合框中有更多项目时,组合框将显示listpicker弹出窗口.如果我选择第一个并向下滚动,则多个项目将显示为已选中.但ComboBox的SelectedItem将是我选择的那个.我修改了ListPickerFlyout的样式并关闭了ListView的虚拟化.如果我这样做,ListView将不会保留SelectedItem.这是ComboBox的错误吗?有没有解决这个问题的方法
这是我修改过的风格
<DataTemplate x:Key="ListPickerFlyoutPresenterContentTemplate" >
<ListView VirtualizingStackPanel.VirtualizationMode="Recycling" SelectionMode="Single" >
<!--<ListView.ItemsPanel>
<ItemsPanelTemplate>
<VirtualizingStackPanel/>
</ItemsPanelTemplate>
</ListView.ItemsPanel>-->
<ListView.ItemContainerStyle>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ListViewItem">
<Border x:Name="OuterContainer" RenderTransformOrigin="0.5,0.5">
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CommonStates">
<VisualState x:Name="Normal" />
<VisualState x:Name="Pressed"/>
<VisualState x:Name="Disabled"/>
<VisualStateGroup.Transitions>
<VisualTransition From="Pressed" To="Normal" />
</VisualStateGroup.Transitions>
</VisualStateGroup>
<VisualStateGroup x:Name="SelectionStates">
<VisualState x:Name="Unselected" />
<VisualState x:Name="Selected">
<Storyboard>
<DoubleAnimation Storyboard.TargetName="CheckGlyph" Storyboard.TargetProperty="Opacity" Duration="0" To="1" />
<DoubleAnimation Storyboard.TargetName="SelectedCheckMark" Storyboard.TargetProperty="Opacity" Duration="0" To="1" />
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="contentPresenter" Storyboard.TargetProperty="Foreground" Duration="0">
<DiscreteObjectKeyFrame KeyTime="0" Value="Green" />
</ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentBorder" Storyboard.TargetProperty="Background">
<DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource ListPickerFlyoutPresenterSelectedItemBackgroundThemeBrush}" />
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</VisualState> …Run Code Online (Sandbox Code Playgroud) 我正在使用ListPicker,但很难让设计工作.我已经包括了我做过的测试:
<ControlTemplate x:Key="listpicker_style" TargetType="toolkit:ListPicker">
<StackPanel>
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="PickerStates">
<VisualState x:Name="Normal"/>
<VisualState x:Name="Highlighted">
<Storyboard>
<ObjectAnimationUsingKeyFrames
Storyboard.TargetName="UserControl"
Storyboard.TargetProperty="Foreground"
Duration="0">
<DiscreteObjectKeyFrame
Value="{StaticResource PhoneTextBoxForegroundBrush}"
KeyTime="0"/>
</ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames
Storyboard.TargetName="Border"
Storyboard.TargetProperty="Background"
Duration="0">
<DiscreteObjectKeyFrame
Value="{StaticResource PhoneTextBoxEditBackgroundColor}"
KeyTime="0"/>
</ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames
Storyboard.TargetName="Border"
Storyboard.TargetProperty="BorderBrush"
Duration="0">
<DiscreteObjectKeyFrame
Value="{StaticResource PhoneTextBoxEditBorderBrush}"
KeyTime="0"/>
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
<VisualState x:Name="Disabled">
<Storyboard>
<ObjectAnimationUsingKeyFrames
Storyboard.TargetName="Border"
Storyboard.TargetProperty="Background"
Duration="0">
<DiscreteObjectKeyFrame
Value="{StaticResource TransparentBrush}"
KeyTime="0"/>
</ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames
Storyboard.TargetName="Border"
Storyboard.TargetProperty="BorderBrush"
Duration="0">
<DiscreteObjectKeyFrame
Value="{StaticResource PhoneDisabledBrush}"
KeyTime="0"/>
</ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames
Storyboard.TargetName="UserControl"
Storyboard.TargetProperty="Foreground"
Duration="0">
<DiscreteObjectKeyFrame
Value="{StaticResource PhoneDisabledBrush}"
KeyTime="0"/>
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<ContentControl
Content="{TemplateBinding Header}"
ContentTemplate="{TemplateBinding …Run Code Online (Sandbox Code Playgroud) 我正在尝试在Windows Phone 7 UserControl中对ListPicker的SelectedIndex属性进行双向绑定.
当我设置DataContext时,它引发以下异常:
SelectedIndex must always be set to a valid value.
这是XAML代码
<Grid x:Name="LayoutRoot">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<toolkit:ListPicker
Grid.Row="0"
x:Name="List1"
SelectionChanged="Picker_SelectionChanged"
SelectedIndex="{Binding PickerSelectedIndex, Mode=TwoWay}"
ItemTemplate="{StaticResource PickerTemplate}"
ItemsSource="{Binding MyList}"/>
</Grid>
Run Code Online (Sandbox Code Playgroud)
和DataContext背后的代码
private ObservableCollection<MyClass> myList = null;
public ObservableCollection<MyClass> MyList
{
get { return this.myList; }
set
{
if (value != this.myList)
{
this.myList= value;
NotifyPropertyChanged("MyList");
this.PickerSelectedIndex = 0;
}
}
}
private int pickerSelectedIndex = 0;
public int PickerSelectedIndex
{
get
{
return this.pickerSelectedIndex;
} …Run Code Online (Sandbox Code Playgroud) 我在WP7上有以下XAML代码:
<toolkit:ListPicker x:Name="ListPickerBwFactors" ItemsSource="{Binding BwFactors}"
cal:Message.Attach="[Event SelectionChanged]=[Action ChangeBinarizeFactor(ListPickerBwFactors.ItemSelected)]">
</toolkit:ListPicker>
Run Code Online (Sandbox Code Playgroud)
我收到错误:Target必须是FrameworkElement或CollectionViewSource
我想要做的就是从ListPicker传递给我的VM,SelectedItem.我究竟做错了什么 ?
我有一个具有以下结构的ListPicker:
toolkit:ListPicker x:Name="mListPicker" HorizontalAlignment="Right" Margin="0,75,43,0" Width="100" VerticalAlignment="Top">
< toolkit:ListPickerItem Content="5"/>
< toolkit:ListPickerItem Content="10"/>
< toolkit:ListPickerItem Content="15"/>
< toolkit:ListPickerItem Content="20"/>
< toolkit:ListPickerItem Content="25"/>
< toolkit:ListPickerItem Content="30"/>
< /toolkit:ListPicker>
Run Code Online (Sandbox Code Playgroud)
每当我尝试运行此命令时,会出现以下消息:
System.Windows.Markup.XamlParseException occurred
Message= [Line: 0 Position: 0]
--- Inner Exception ---
The parameter is incorrect.
LineNumber=0
LinePosition=0
StackTrace:
at MS.Internal.XcpImports.MethodEx(IntPtr ptr, String name, CValue[] cvData)
at MS.Internal.XcpImports.MethodEx(DependencyObject obj, String name)
at MS.Internal.XcpImports.FrameworkElement_ApplyTemplate(FrameworkElement frameworkElement)
at System.Windows.FrameworkElement.ApplyTemplateInternal()
at System.Windows.Controls.ScrollContentPresenter.HookupScrollingComponents()
at System.Windows.Controls.ScrollContentPresenter.OnApplyTemplate()
at System.Windows.FrameworkElement.OnApplyTemplate(IntPtr nativeTarget)
at MS.Internal.XcpImports.MeasureNative(IntPtr element, Single inWidth, Single inHeight)
at MS.Internal.XcpImports.UIElement_Measure(UIElement element, …Run Code Online (Sandbox Code Playgroud) 我正在为一个新项目尝试使用caliburn.micro框架,但我坚持使用绑定ListPicker(工具包中的那个).当我将控件更改为简单的DropDown时,一切都按预期工作.我假设DropDown工作正常,因为这里实现了默认约定:
AddElementConvention<Selector>(Selector.ItemsSourceProperty, "SelectedItem", "SelectionChanged")
.ApplyBinding = (viewModelType, path, property, element, convention) => {
if (!SetBinding(viewModelType, path, property, element, convention))
return false;
ConfigureSelectedItem(element, Selector.SelectedItemProperty,viewModelType, path);
ApplyItemTemplate((ItemsControl)element, property);
return true;
};
Run Code Online (Sandbox Code Playgroud)
ListPicker没有实现Selector,所以我试图在我的引导程序中添加一个自定义约定:
static void AddCustomConventions() {
AddElementConvention<ListPicker>(ListPicker.ItemsSourceProperty, "SelectedItem", "SelectionChanged")
.ApplyBinding = (viewModelType, path, property, element, convention) => {
ConventionManager.ConfigureSelectedItem(element, ListPicker.SelectedItemProperty,viewModelType, path);
return true;
};
}
Run Code Online (Sandbox Code Playgroud)
不幸的是,这不起作用.你能帮我吗?
c# silverlight-toolkit windows-phone-7 caliburn.micro listpicker
我试图在wp7中创建一个下拉列表,它将具有文本属性和值.
我将使用什么控件,是否有人有一个显示如何将其绑定到Odata的exmaple?
谢谢
我想确定当前在ListPicker中选择的项目的名称.我不确定在SelectionChanged事件中要做什么来获取项目的名称.
XAML
<Grid.Resources>
<DataTemplate x:Name="PickerItemTemplate">
<TextBlock Text="{Binding Name}"/>
</DataTemplate>
</Grid.Resources>
<toolkit:ListPicker x:Name="ThemeListPicker" Header="{Binding Path=LocalizedResources.SettingsPage_ThemeListPicker_Header, Source={StaticResource LocalizedStrings}}"
ItemTemplate="{StaticResource PickerItemTemplate}"
SelectionChanged="ThemeListPicker_SelectionChanged"/>
Run Code Online (Sandbox Code Playgroud)
XAML.CS
protected override void OnNavigatedTo(NavigationEventArgs e)
{
base.OnNavigatedTo(e);
themeList = new List<Theme>();
themeList.Add(new Theme() { Name = "light" });
themeList.Add(new Theme() { Name = "dark" });
ThemeListPicker.ItemsSource = themeList;
}
private void ThemeListPicker_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
//get the name of the current item in the listpicker?
}
Run Code Online (Sandbox Code Playgroud) 这是空闲时的样子:

在这里,当我点击它时,应该弹出全屏选择模式(根据我读过的内容):

如您所见,它似乎没有打开全屏选择模式.
这是我的XAML:
<phone:PhoneApplicationPage
x:Class="GameLense.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:toolkit="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit"
mc:Ignorable="d" d:DesignWidth="480" d:DesignHeight="768"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneForegroundBrush}"
SupportedOrientations="Portrait" Orientation="Portrait"
shell:SystemTray.IsVisible="True">
<Grid>
<Grid.Resources>
<DataTemplate x:Name="PickerItemTemplate">
<StackPanel Orientation="Horizontal">
<Border Background="Transparent" Width="34" Height="34">
<Image Source="{Binding ImagePath}" Margin="12 0 0 0"
VerticalAlignment="Center"
HorizontalAlignment="Center"
Stretch="Fill"/>
</Border>
<TextBlock Text="{Binding Name}" Margin="12 0 0 0"/>
</StackPanel>
</DataTemplate>
<DataTemplate x:Name="PickerFullModeItemTemplate">
<StackPanel Orientation="Horizontal">
<Border Background="Gold" Width="34" Height="34">
<Image Source="{Binding ImagePath}" Margin="12 0 0 0" VerticalAlignment="Center" HorizontalAlignment="Center" />
</Border>
<TextBlock Text="{Binding Name}" Margin="12 0 0 …Run Code Online (Sandbox Code Playgroud) 我在WCF中有一个类:
[DataContract]
public class Usuario
{
[DataMember]
public int ID { get; set; }
[DataMember]
public string Nombre { get; set; }
[DataMember]
public string Contraseña { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
在WP7 Proyect中从WCF读取ObservableCollection并加载ListPicker:
lpUsuarios.ItemSource = listUsuarios;
Run Code Online (Sandbox Code Playgroud)
这项工作还可以.
现在,在WP7中使用"Usuario _usuario = new Usuario()"作为局部变量.
问题是,如果我使用IsolatedStorage保存变量_usuario然后加载并应用:lpUsuarios.SelectedItem = _usuario,则会导致错误:SelectedItem必须始终设置为有效值.
例:
Usuarios _usuario = new Usuario();
private void ButtonSave_Click(object sender, RoutedEventArgs e)
{
var settings = IsolatedStorageSettings.ApplicationSettings;
_usuario = lpUsuarios.SelectedItem as Usuario;
settings.Add("test", _usuario);
settings.Save();
}
Run Code Online (Sandbox Code Playgroud)
现在,关闭应用程序,然后打开:
private void ButtonLoad_Click(object sender, RoutedEventArgs e)
{
settings.TryGetValue<Usuario>("test", …Run Code Online (Sandbox Code Playgroud)