我有一个ListBox与ListBoxItem使用DataTemplate,使用Expander作为容器.问题是,Expander似乎正在吃掉Click事件(确切地说是HeaderSite一部分Expander),SelectedItem如果我点击Expander它,我就永远不会得到(但是如果你点击它ListBoxItem自己就行了).
关于如何Expander与之搭配的任何想法ListBox?
这是一个简化的Xaml,可以重现问题(不需要代码):
编辑代码更新,以更接近我的实际模板,但截图仍然是从以前的版本(问题是相同的 - 这只是为了澄清第一个答案的问题)
<Window x:Class="ListBoxSample.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<StackPanel>
<TextBlock>
<Run Text="Selected Item" />
<Run Text="{Binding ElementName=ListBox, Path=SelectedItem}" />
</TextBlock>
<ListBox x:Name="ListBox">
<ListBoxItem>
<Expander Header="Expandable Stuff 1">
<ListBox>
<ListBoxItem>1.1</ListBoxItem>
<ListBoxItem>1.2</ListBoxItem>
</ListBox>
</Expander>
</ListBoxItem>
<ListBoxItem>
<Expander Header="Expandable Stuff 2">
<ListBox>
<ListBoxItem>2.1</ListBoxItem>
<ListBoxItem>2.2</ListBoxItem>
</ListBox>
</Expander>
</ListBoxItem>
</ListBox>
</StackPanel>
</Window>
Run Code Online (Sandbox Code Playgroud)
屏幕截图是预编辑的 …
我有一个ListBox是有它ItemsSource绑定到(正确)实现了一个自定义类INotifyCollectionChanged和SelectedItem绑定到一个ViewModel的字段.
问题是,当我SelectedItem从ItemsSource集合中删除当前时,它会立即将选择更改为相邻项.如果它只是删除了选择,我非常希望.
这对我来说是个问题的原因如下.的ItemsSource类包含从其他收集元件,要么满足一些(运行时恒定期间)谓词或是Active.存在Active与存在"同步" SelectedItem(有原因).因此,ListBox只有当它被选中时才允许一个项目被允许,这意味着当用户选择其他项目时它可能会消失.
我的函数(深入"模型")在SelectedItem被改变时被调用:
//Gets old Active item
var oldActiveSchema = Schemas.FirstOrDefault(sch => sch.IsActive);
//Makes the new Item active (which triggers adding it into `ItemsSource` in case it didn't satisfy the Predicate)
((PowerSchema)newActiveSchema).IsActive = true;
//Triggers PropertyChanged on ViewModel with the new Active item
CurrentSchema = newActiveSchema;
RaisePropertyChangedEvent(nameof(CurrentSchema)); (#1)
//Changes the old item so it stops …Run Code Online (Sandbox Code Playgroud) 嗨,我正在开发一个WPF应用程序,我在其中有一个WPF浏览器控件导航到URL"http:....",它采用Windows凭据.
问题是:当我复制粘贴URL时,它只是执行身份验证并正常工作.但是当从WPF Web浏览器导航时,它并没有获得Windows的信誉.
public void StartNavigation()
{
if (!String.IsNullOrEmpty(URL) && webBrowser.Source == null)
webBrowser.Navigate(new Uri(URL));
}
<UserControl x:Class="Slb.iDistrict.Prism.Module.JobEmbeddedBrowser.View.JobEmbeddedBrowserView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d" Loaded="UserControl_Loaded"
d:DesignHeight="300" d:DesignWidth="300">
<Grid>
<WebBrowser Name="webBrowser"/>
</Grid>
Run Code Online (Sandbox Code Playgroud)
UserControl_Loaded> Event将调用StartNavigation()方法.我的网址看起来像这样:" http://www.test.cmp.com/App/Login/SingleSignon.aspx?Screen=sample&BL=cc&JN=12345 "当我执行导航我的浏览器时.源重置为某些default.aspx该网站的页面.我认为这是因为获取Windows身份验证信息失败.我试图在网上找到一些帮助,但没有找到合适的结果.
问题是什么?
我正在尝试检索一些令人沮丧的Active Directory属性:
我很难找到他们两个.
例如,对于msexchmailboxsecuritydescriptor,如果我的代码类似于以下内容:
DirectoryEntry deresult = result.GetDirectoryEntry();
byte[] bteMailACL =(byte[])deresult.Properties["msexchmailboxsecuritydescriptor"].Value;
Run Code Online (Sandbox Code Playgroud)
它抱怨我不能将System .__ ComObject强制转换为System.Byte [],但我看到了几个使用类似上面代码的例子.
我如何理解这些信息?
我有一个类型的ListBox绑定.MyCollectionIEnumerable<string>
<ListBox x:Name="ListBox" ItemsSource="{Binding MyCollection, Mode=OneWay}" SelectionMode="Multiple"/>
Run Code Online (Sandbox Code Playgroud)
我有另一个List<string> SubCollection包含的子集MyCollection
无论什么时候SubCollection改变,我都希望按照这个改进SelectedItems来突出显示SubCollection
有没有Binding,Behaviour或任何其他方式来实现这一目标?
编辑:
让我们说我有一定的ListBox约束力MyCollection { "Orange", "Mango", "Stawberry", "Pineapple" }
让我们假设我按下一个按钮从数据库加载数据,结果是"橙色","芒果",然后放入SubCollection.ListBox现在应该有"橘子","芒果"作为它的SelectedItems.