我有一些麻烦搞清楚如何设置正确的DataContext
一个ContextMenu
.
我有一组视图模型,他们是一个ItemsControl
.每个视图模型都有一组项目,这些项目也是另一个项目的来源ItemsControl
.每个项目用于绘制具有的图像ContextMenu
.将MenuItems
在ContextMenu
需要绑定到视图模型的一个命令,但是PlacementTarget
的ContextMenu
是指向单个项目.
我的Xaml看起来像这样:
<ItemsControl ItemsSource="{Binding Markers"}>
<ItemsControl.ItemTemplate>
<DataTemplate>
<ItemsControl ItemsSource="{Binding Items}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<Image>
<Image.ContextMenu>
<ContextMenu>
<MenuItem Header="Edit" Command="{Binding EditCommand}" />
</ContextMenu>
</Image.ContextMenu>
</Image>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
Run Code Online (Sandbox Code Playgroud)
我如何设置DataContext
的ContextMenu
,以该项目的相应的父视图模型?
......这没有任何意义.TT
在我的Application_Startup
事件处理程序中,我的代码看起来有点像这样:
private void Application_Startup(object sender, StartupEventArgs e)
{
string errorMessage;
if(CheckStartUpConditions(out errorMessage))
{
(new MainWindow()).Show();
}
else
{
MessageBox.Show(errorMessage, "Application Startup",
MessageBoxButton.OK, MessageBoxImage.Error);
Shutdown();
}
}
private bool CheckStartUpConditions(out string errorMessage)
{
errorMessage = string.Empty;
if(...)
errorMessage += "Please login to xxx. ";
if(...)
errorMessage += "Please install xxx.";
if(string.IsNullOrEmpty(errorMessage))
return true;
else
return false;
}
Run Code Online (Sandbox Code Playgroud)
在进入"POOF!"之前,消息框会短暂出现一段时间.它不等我单击"确定"或"X"按钮.我真的很难过为什么会这样,所以任何帮助都会非常感激.
我已经尝试将这个电话评论为Shutdown
只是为了踢和笑,它仍然表现得一样.
此外,该应用程序也有一个SplashScreen
,所以我不知道这是否会影响这一点.
编辑:如果有帮助,我添加了更多代码.消息框显示正确的错误消息.只是不会停留足够长的时间让用户阅读它.> :(
编辑第2部分:好的......我想我找到了罪魁祸首.:(我改变了我正在使用的图像上的构建操作,因为我从SplashScreen到我的飞溅到无,并且消息框现在将保留并等待用户输入.我不明白为什么SplashScreen与MessageBox一起拧紧.>: (
我有一个需要引用System.Xaml的VS2010项目.我转到添加引用,搜索.NET引用,它不在那里.:?
我也仔细检查了GAC,没有这样的运气.
我只是无法弄清楚为什么它不在机器上.本机安装了.NET 3.5 SP1和.NET 4.0.
我宁愿对这个问题有一个简单的解释,而不必诉诸重新安装框架.TT
有什么想法吗?非常感激.
我正在将Button的内容设置为图像.它看起来像这样:
<Button>
<Image Source="pack://application:,,,/NavigationImages/nav_up_left.png" />
</Button>
Run Code Online (Sandbox Code Playgroud)
在我的项目中,我有一个名为NavigationImages的子文件夹,在该文件夹中是图像文件nav_up_left.png.
当我查看Designer时,图像出现,但是在运行时,我收到一个IOException错误,说它找不到资源.
Build Action设置为Resource.
实际上,这在一个项目中运作良好.但是当我将它复制到另一个项目上时,它失败了.这似乎是一个非常简单的问题,但我发现自己很难过,准备开始拔头发了.@ _ @
非常感谢您的想法和建议!
我希望自定义基本WPF的外观TickBar
.我想知道是否有一种简单的方法可以使用控件模板:
我希望用数字代替刻度线上的刻度.我希望数字的位置对应于滑块的值(很像链接中的图片).
我已经搜索了一个建议,我发现创建了一个继承自TickBar
并覆盖它的OnRender
方法的类.
我更愿意找到一个不涉及这个问题的解决方案.我真的希望使用控件模板来做到这一点.所以,如果有一个这样的解决方案,建议将不胜感激!:)
如何强制DataGridView释放对绑定DataSet的引用?
我们在DataGridView中显示了一个相当大的数据集,并注意到DataGridView关闭后资源没有被释放.如果用户反复查看此报告,则最终会出现内存不足异常.ANTS Memory Profiler确认DGV尽管dgv.DataSource
设置为null 仍保持引用.
我遇到的问题与ControlTemplate
为ToggleButton
我创造.
当按钮为时Checked
,ColorAnimation
触发a并且控件的背景改变颜色.但是,如果用户进入MouseOver
状态,则会触发另一个影响按钮背景的动画.
当鼠标不再处于该MouseOver
状态时,控件不会返回到处于该Checked
状态时应该处于的颜色.我不确定为什么在MouseOver
触发状态时这种情况不会持续存在.
在VisualStateManager
我的部分ControlTemplate
看起来有点儿像这样:
<VisualStateManger.VisualStateGroups>
<VisualStateGroup x:Name="CommonStates">
<VisualState x:Name="Normal"></VisualState>
<VisualState x:Name="MouseOver">
<Storyboard>
<ColorAnimation Storyboard.TargetName="BackgroundBorder"
Storyboard.TargetProperty="(Border.Background).(SolidColorBrush.Color)"
To="Gold" Duration="0:0:0.3" />
</Storyboard>
</VisualState>
</VisualStateGroup>
<VisualStateGroup x:Name="CheckedStates">
<VisualState x:Name="Checked">
<Storyboard>
<ColorAnimation Storyboard.TargetName="BackgroundBorder"
Storyboard.TargetProperty="(Border.Background).(SolidColorBrush.Color)"
To="PaleGoldenrod" Duration="0:0:0.3" />
</Storyboard>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
Run Code Online (Sandbox Code Playgroud) 我已经使用了ItemsPanelTemplate
其他控件,比如ListBox
,所以我认为做同样的事情TabControl
会很简单.
显然,我错过了一些东西而且TabControl
完全无视我放置的内容ItemsPanelTemplate
.
我有xaml,看起来有点像这样:
<TabControl TabStripPlacement="Right" ItemsSource="{Binding Components}">
<TabControl.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel />
</ItemsPanelTemplate>
</TabControl.ItemsPanel>
</TabControl>
Run Code Online (Sandbox Code Playgroud)
我已经尝试更换WrapPanel
,UniformGrid
看看是否有差异,它的行为相同.我确实有一个ControlTemplate
for TabItem
,但我尝试删除它并没有任何区别所以我认为这不会影响我的问题.
我有一个我作为用户控件创建的组合框(它实际上由标签,组合框和文本框组成).我正在尝试将数据集绑定到组合框数据源,但我在ValueMember/Display成员上不断收到错误消息:
Cannot bind to the new display member - newdisplay member
Cannot bind to the new value member - parameter name: value
Run Code Online (Sandbox Code Playgroud)
我以为我为usercontrol正确编码了所有内容:
public partial class ucComboBox : UserControl
{
#region Properties (6)
private bool isEditableReadOnly;
private bool ArrVisible;
private string _value;
private string _name;
public string value
{
get { return _value ; }
set { _value = value; }
}
public string name
{
get { return _name; }
set { _name = value; }
}
}
Run Code Online (Sandbox Code Playgroud)
我在usercontrol中有一些其他属性和事件,但它们不应该是问题. …
在Angular 2
您可以创建本地模板变量更容易地访问HTML元素.
<input #name type="text">
<button (click)="submit(name.value)">Submit</button>
Run Code Online (Sandbox Code Playgroud)
在Aurelia有相同的功能吗?
wpf ×7
c# ×4
.net ×3
winforms ×2
angular ×1
aurelia ×1
combobox ×1
contextmenu ×1
datacontext ×1
html ×1
image ×1
itemspanel ×1
javascript ×1
memory-leaks ×1
messagebox ×1
pack-uri ×1
slider ×1
tabcontrol ×1
togglebutton ×1
visualstates ×1
wpf-controls ×1