从Collection创建MenuItems(Create MenuItems from Collection)
我试图创建收集项的MenuItems - 并失败。 详细说明:我有一个简单的类ClassA,它定义了一个字符串属性'HeadText'。 在我的MainViewModel中,我定义了一个ObservableCollection属性。 该系列包含3个项目。 现在在XAML中,我想创建这三个ClassA类型的MenuItems。 我做了以下事情:
<Window.Resources> <CompositeCollection x:Key="CollA"> <ItemsControl ItemsSource="{Binding Path=MItems}"> <ItemsControl.ItemTemplate> <DataTemplate> <MenuItem Header="{Binding HeadText}"/> </DataTemplate> </ItemsControl.ItemTemplate> </ItemsControl> </CompositeCollection> </Window.Resources> <Grid> <Menu DockPanel.Dock="Top" ItemsSource="{Binding Source={StaticResource CollA}}"/> </Grid>
但我得到的只是一个空的菜单栏。 我有什么想法可以做到这一点?
viewmodel和类ClassA:
public class MainVM { public MainVM() { _mItems.Add(new ClassA() { HeadText = "A" }); _mItems.Add(new ClassA() { HeadText = "B" }); _mItems.Add(new ClassA() { HeadText = "C" }); } private ObservableCollection<ClassA> _mItems = new ObservableCollection<ClassA>(); public ObservableCollection<ClassA> MItems{ get { return _mItems; } } } public class ClassA { public ClassA() { } public String HeadText { get; set; } }
提前致谢。
编辑:
如果我写这个,它的工作原理:
<Menu DockPanel.Dock="Top" ItemsSource="{Binding MItems}"> <Menu.ItemContainerStyle> <Style TargetType="MenuItem" BasedOn="{StaticResource {x:Type MenuItem}}"> <Setter Property="Header" Value="{Binding HeadText}"/> </Style> </Menu.ItemContainerStyle> </Menu>
但我想以另一种方式做到这一点。 我很感兴趣为什么另一种方式不起作用。
i tried to create MenuItems of collection items - and failed. In detail: I have a simple class ClassA that defines a string-property 'HeadText'. In my MainViewModel i defined an ObservableCollection property. The collection is filled with 3 items. Now in XAML i want to create MenuItems of these 3 items of type ClassA. I did the following:
<Window.Resources> <CompositeCollection x:Key="CollA"> <ItemsControl ItemsSource="{Binding Path=MItems}"> <ItemsControl.ItemTemplate> <DataTemplate> <MenuItem Header="{Binding HeadText}"/> </DataTemplate> </ItemsControl.ItemTemplate> </ItemsControl> </CompositeCollection> </Window.Resources> <Grid> <Menu DockPanel.Dock="Top" ItemsSource="{Binding Source={StaticResource CollA}}"/> </Grid>
But all i get is an empty menu bar. Any ideas how i can do this?
The viewmodel and the class ClassA:
public class MainVM { public MainVM() { _mItems.Add(new ClassA() { HeadText = "A" }); _mItems.Add(new ClassA() { HeadText = "B" }); _mItems.Add(new ClassA() { HeadText = "C" }); } private ObservableCollection<ClassA> _mItems = new ObservableCollection<ClassA>(); public ObservableCollection<ClassA> MItems{ get { return _mItems; } } } public class ClassA { public ClassA() { } public String HeadText { get; set; } }
Thanks in advance.
Edit:
If i write this, it works:
<Menu DockPanel.Dock="Top" ItemsSource="{Binding MItems}"> <Menu.ItemContainerStyle> <Style TargetType="MenuItem" BasedOn="{StaticResource {x:Type MenuItem}}"> <Setter Property="Header" Value="{Binding HeadText}"/> </Style> </Menu.ItemContainerStyle> </Menu>
But i want to do it the other way. And i'm interested why the other way does not work.
原文:https://stackoverflow.com/questions/28432867
最满意答案
将text-align设置为left。
<fieldset style="text-align:left;">
set text-align to left.
<fieldset style="text-align:left;">
相关问答
更多-
使用Chrome打开Internet Explorer / Firefox等窗口(Open a Internet explorer/Firefox etc window with Chrome)[2023-05-31]
如果JS可以调用firefox.exe ,它也可以调用nasty_trojan.exe 。 您可以做的最好的事情是生成自定义链接服务器端,并说“将此链接粘贴到您的其他浏览器中。 除非你真的很喜欢,在这种情况下你需要渲染页面服务器端,ala http://browsershots.org/ 。 如果你把它写成chrome扩展名,就有可能做到这一点,因为那些有一定程度的信任,但页面上的JS仍然在其沙箱中。 If JS can call firefox.exe, it could also call nasty_ ... -
你必须修改你的CSS来对齐所有浏览器中的下拉箭头,包括IE11。 请使用这个CSS。 #nav li{ display: inline-block; position: relative; /*Added Line*/ } #nav ul li.active:after { border-left: 20px solid transparent; border-right: 20px solid transparent; content: ""; border-top: 13px solid rg ...
-
将text-align设置为left。
-
打开Internet Explorer并按F12。 这将打开Developer ToolBar。 顶部有浏览器模式。 您可以在那里更改浏览器的渲染引擎。 Open Internet Explorer and press F12. This will open the Developer ToolBar. At the top it has Browser Mode. You can change the browser's rendering engine there.
-
-moz-box-shadow: 0 0 20px #000; 仅适用于FireFox。 你可以使用box-shadow: 0 0 20px #000; IE <9需要一些帮助。 你需要这样的东西 filter:progid:DXImageTransform.Microsoft.Blur(PixelRadius=2,MakeShadow=true,ShadowOpacity=0.20); -ms-filter:"progid:DXImageTransform.Microsoft.Blur(PixelRad ...
-
最后,我解决了我的问题。 如果有人需要答案,我在这里做了什么。 document.all和document.layers都已经过时,已经使用Internet Explorer 6.所以我使用了document.getElementById而不是document.all,如果条件与document.layer一起删除了所有内容。 最后,我没有找到什么document.all,window.sidebar和document.getElementById返回(编辑:这里的答案从Internet Explorer ...
-
在此WWDC 2015视频中 ,声明将用户代理设置为响应式设计模式仅设置UA字符串 ; 而已。 没有模拟或任何。 此外,让IE在OS X上工作既需要巨大的努力,也需要微软和苹果的协作。 我认为这种情况不会发生,尤其是对于非盈利软件的延期。 我知道这个答案并没有解释你的截图,但我不能在没有看到代码的情况下对此进行更多评论,但我的2美分将在css前缀上。 Safari可能会根据用户代理忽略/应用它们,这将解释不同之处。 IE条件标签将成为另一种可能性。 In this WWDC 2015 video, it i ...
-
我解决了三个问题中的两个: 在动画整个页面时(如滚动到内容),您必须同时定位html和body标签,如: $('html, body') 。 以前我只有$('body')所以代码在IE中不起作用。 Chrome需要'body',而IE需要'html',因此总共需要包含两者。 此外,注释被从ajax调用中删除,所以我的flash嵌入,使用特殊条件和IE的HTML注释,回来与IE的错误标签。 这就是IE中没有播放视频的原因。 最后一个问题仍然存在:firefox在打开一个盒子后无法正确地重新组织我网站上的盒子。 ...
-
Internet Explorer和Firefox未在页面上显示所有图像(Internet Explorer and Firefox not showing all images on page)[2024-01-10]
这是因为有问题的图像不是JPEG(或GIF或PNG),而是Google WebP ,而Internet Explorer本身并不支持这样的图像( Firefox和Safari也不支持这种图像)。 最简单的解决方案是将其转换为JPG。 It's because the image in question is not a JPEG (or GIF or PNG) but rather Google WebP, and Internet Explorer does not natively support su ... -
Chrome到Firefox和Internet Explorer的不同空间(Different space in Chrome to Firefox and Internet Explorer)[2022-04-03]
设定线高, tr {line-height:30px} Set line height , tr {line-height:30px}