windows-phone-7 – 如何设置ListBox项的前景色
发布时间:2020-12-14 05:53:07 所属栏目:Windows 来源:网络整理
导读:我在WP7应用程序页面中有一个ListBox,它绑定到名为Location的自定义对象的集合(List).在那个对象是一个名为WMO的字段,当ListBox加载时我想要做的是设置任何绑定列表框项目的foregound颜色具有与我的默认值相同的值…但我似乎无法让这个工作我读过或谷歌搜索
我在WP7应用程序页面中有一个ListBox,它绑定到名为Location的自定义对象的集合(List).在那个对象是一个名为WMO的字段,当ListBox加载时我想要做的是设置任何绑定列表框项目的foregound颜色具有与我的默认值相同的值…但我似乎无法让这个工作我读过或谷歌搜索没有任何帮助.
我知道列表中的项目绑定到数据源但我想要获得该项目的物理表示并更改前景颜色….只是无法弄清楚我是如何做到的,所以如果有人可以帮助我’我很欣赏它. <Grid x:Name="ContentPanel" Grid.Row="1" Margin="0,0" > <ScrollViewer Height="615" HorizontalAlignment="Left" Margin="5,5,5" Name="scrollViewer1" VerticalAlignment="Top"> <ListBox Name="lbxSavedLocs" Height="615" FontSize="22" HorizontalAlignment="Left" VerticalAlignment="Top" Width="470" SelectionChanged="lbxSavedLocs_SelectionChanged" Loaded="lbxSavedLocs_Loaded"> <ListBox.ItemTemplate> <DataTemplate> <StackPanel Orientation="Horizontal"> <TextBlock Width="380" Text="{Binding SiteName}" HorizontalAlignment="Left" /> <TextBlock Width="90" Text="{Binding WMO}" HorizontalAlignment="Center" /> </StackPanel> </DataTemplate> </ListBox.ItemTemplate> </ListBox> </ScrollViewer> </Grid> private void lbxSavedLocs_Loaded(object sender,RoutedEventArgs e) { //Populate the listbox from our saved locations. lbxSavedLocs.ItemsSource = gl.savedLocs.OrderBy(x => x.SiteName); foreach (Location itm in lbxSavedLocs.Items) { if (loc.WMO == gl.defaultWMO) { //GET AN "INVALID CAST" EXCEPTION HERE: ((ListBoxItem)itm).Foreground = new SolidColorBrush(Color.FromArgb(255,255,255)); } } //Hopefully this produces a redraw of the ListBox. lbxSavedLocs.InvalidateArrange(); } 解决方法
这是一种方式……我认为它有效
要绑定的属性是Foreground,所以 <Grid x:Name="ContentPanel" Grid.Row="1" Margin="0,0" > <ScrollViewer Height="615" HorizontalAlignment="Left" Margin="5,5" Name="scrollViewer1" VerticalAlignment="Top"> <ListBox Name="lbxSavedLocs" Height="615" FontSize="22" HorizontalAlignment="Left" VerticalAlignment="Top" Width="470" SelectionChanged="lbxSavedLocs_SelectionChanged" Loaded="lbxSavedLocs_Loaded"> <ListBox.ItemTemplate> <DataTemplate> <StackPanel Orientation="Horizontal"> <TextBlock Width="380" Text="{Binding SiteName}" Foreground="{binding forgroundColor}" HorizontalAlignment="Left" /> <TextBlock Width="90" Text="{Binding WMO}" Foreground="{binding forgroundColor}" HorizontalAlignment="Center" /> </StackPanel> </DataTemplate> </ListBox.ItemTemplate> </ListBox> </ScrollViewer> </Grid> 在程序中提出了适当的条件,你填充列表框以使用foregroundColor选择正确的Forground 使用类containsin填充列表框 class lisboxItem { public string SiteName{get;set;} public string forgroundColor{get;set;} public string WMO{get;set;} } 创建一个List< listboxItem> items = new List< listboxItem>(); 并在循环中填充列表项,其中u给出您想要的条件. 之后呼叫lbxSavedLocs.ItemSource =项目 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- windows – Haskell,GHC,win32,cairo
- windows-7 – “Windows Virtual PC”和“Microsoft Virtua
- active-directory – SPN是否特定于Windows和Active Direct
- .net – 有没有理由切换到用于Windows窗体开发的Visual Stu
- .net – 项目引用DLL版本地狱
- windows – 如何用cmake指定带有空格的路径?
- Windows – UAC是否会失去以普通用户身份运行的需求?
- 几个简单的windows API
- 人尽可用的Windows技巧小贴士之下篇
- windows – 如何在Win7中模拟重新启动以测试应用程序冷启动
推荐文章
站长推荐
- 使用System.Windows.Forms的C#不存在
- 什么是在Windows上运行的最佳维基?
- windows – 使用MinGW编译凭据提供程序
- 未来的Windows Server路线图?
- WPF DataGrid与Windows窗体DataGridView
- 哪个Windows版本的Windows ANSI Western(cp 1252
- Windows Server 2016-客户端加域准备工作
- wds – Windows部署服务器在en-GB时将图像列为en
- This application failed to start because it c
- windows-phone-7 – 在窗口的手机上刷新广告
热点阅读