我有与引用完全相同的问题(在这里采取,但没有回答):
我通过StackPanel.Childrens.Add()将控件添加到StackPanel.
但是我所看到的 - 我添加的所有控件都处于相同的位置并相互重叠.它们不在StackPanel内部布局.
甚至StackPanel.UpdateLayout()也没有给我带来什么.
我对我来说是想添加Canvases(是的,我确实需要它们)StackPanel.有任何想法吗?
是否可以将多个命令绑定到按钮.
我有一个用户控件,我在我的主应用程序(父应用程序)中调用.
我想在两个控件(用户控件以及主窗口)上处理单击命令.但是我只能得到一个.
有什么方法可以让我得到这个.
任何帮助都非常感谢.
代码片段:
public class MainWindowFooterCommands
{
public static readonly RoutedUICommand FooterClickLocalCommand = new RoutedUICommand("Local Button Command", "FooterClickLocalCommand", typeof(MainWindowFooterCommands));
}
private void MainWindowFooterBindCommands()
{
CommandBinding cmdBindingBXClick = new CommandBinding(MainWindowFooterCommands.FooterClickLocalCommand);
cmdBindingBXClick.Executed += ClickCommandHandler;
CommandBindings.Add(cmdBindingBXClick);
}
void ClickCommandHandler(object sender, ExecutedRoutedEventArgs e)
{
//Do Something
}
//Parent Control holding an instance of the footer control.
class MainWindow {
public MainWindow()
{
CommandBinding cmdBindingBXClick1 = new CommandBinding(MainWindowFooterCommands.BXClickMainWindowCommand);
cmdBindingBXClick1.Executed += LoadParent;
CommandBindings.Add(cmdBindingBXClick1);
}
public void LoadParent(object sender, ExecutedRoutedEventArgs e)
{
LoadParentWindow();
} …Run Code Online (Sandbox Code Playgroud) 这里有一个适用于所有XAML向导:WPF Toolkit Calendar控件(2009年6月)似乎有一个错误.修改ControlTemplate日历时,只会出现错误,特别是PART_CalendarItem.
在这条消息的最后,我已经将XAML包含在一个(Blend 3.0)窗口中,该窗口声明Calendar并指定了它ControlTemplate.控件模板是Calendar控件模板的未修改副本,我通过编辑Calendar控件和PART_CalendarItem控件的控件模板(在Blend中)的副本来获得该模板.
在XAML的第78行(用下面的注释"EXCEPTION"标记),在控件的标题上VisualStateManager指定TextColor一个鼠标悬停Month.但是,在控件模板中,文本颜色被分配给Grid保存Month按钮的文本颜色,而不是月份按钮本身.当为日历分配未修改的控件模板时,这会导致VS2008和Blend 3.0中的异常,如下面的XAML中所示.
我无法弄清楚如何修改控件模板以消除错误,而不是删除鼠标悬停突出显示.我想保留它,但我不知道该TextColor属性应该针对什么.有什么建议?谢谢你的帮助!
XAML标记
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:Custom="http://schemas.microsoft.com/wpf/2008/toolkit"
x:Class="WpfApplication1.MainWindow"
x:Name="Window"
Title="MainWindow"
Width="640" Height="480">
<Window.Resources>
<Style x:Key="CalendarStyle1" TargetType="{x:Type Custom:Calendar}">
<Setter Property="Foreground" Value="#FF333333"/>
<Setter Property="Background">
<Setter.Value>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="#FFE4EAF0" Offset="0"/>
<GradientStop Color="#FFECF0F4" Offset="0.16"/>
<GradientStop Color="#FFFCFCFD" Offset="0.16"/>
<GradientStop Color="White" Offset="1"/>
</LinearGradientBrush>
</Setter.Value>
</Setter>
<Setter Property="BorderBrush">
<Setter.Value>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="#FFA3AEB9" Offset="0"/>
<GradientStop Color="#FF8399A9" Offset="0.375"/> …Run Code Online (Sandbox Code Playgroud) 有谁知道如何做到这一点?我对WPF GridView(ListView View = GridView)的稀缺文档/示例代码感到非常惊讶.
有没有办法重用WPF中节点旁边出现的简单展开[+]和折叠[-]按钮TreeView?我想在我的应用程序的其他地方有一个类似的图形来扩展和折叠一些控件.
所以我遇到了试图实现MVVM的问题.AFAIK在ViewModel类中执行方法的最佳方法是通过CommandBinding.
<Button Command={Binding DoSomethingCommand} />
Run Code Online (Sandbox Code Playgroud)
只有这次我需要在ListBoxItem上双击一些东西,ListBoxItem不实现ICommandSource.所以我想知道最好的方法是什么,如果有的话.
谢谢!
编辑:
我只是想到了一种方式,但它似乎相当hacky.如果我公开ListBox.DoubleClick事件,我的ViewModel类订阅它并在触发DoubleClick时运行正确的方法怎么办?
我创建了一个用户控件"SearchControl"(它将在其他屏幕中进一步重用.SearchControl - >
<usercontrol name="SearchControl"......>
<stackpanel orientation="horizontal"...>
<TextBox Text"{Binding Path=UserId}"...>
<Button Content="_Search" ....Command="{Binding Path=SearchCommand}"..>
</stackpanel>
</usercontrol>
public partial class SearchControl : UserControl
{
public SearchControl()
{
InitializeComponent();
DataContext=new UserViewModel();
}
}
Run Code Online (Sandbox Code Playgroud)
然后我在窗口"UserSearch"中使用此控件
<window name="UserSearch".............
xmlns:Views="Namespace.....Views">
<Grid>
<Grid.RowDefinitions>
<RowDefinition..../>
<RowDefinition..../>
<RowDefinition..../>
<RowDefinition..../>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition..../>
<ColumnDefinition..../>
</Grid.ColumnDefinitions>
<Views:SearchControl Grid.Row="0" Grid.Colspan="2"/>
<TextBlock Text="User Id" Grid.Row="1" Grid.Column="0"..../>
<TextBox Text="{Binding Path=UserId}" Grid.Row="1" Grid.Column="1".../>
<TextBlock Text="First Name" Grid.Row="2" Grid.Column="0"..../>
<TextBox Text="{Binding Path=FirstName}" Grid.Row="2" Grid.Column="1".../>
<TextBlock Text="Last Name" Grid.Row="3" Grid.Column="0"..../>
<TextBox Text="{Binding Path=LastName}" Grid.Row="3" Grid.Column="1".../>
</Grid> …Run Code Online (Sandbox Code Playgroud) 我的应用程序使用WPF DataGrid.其中一列是模板列,其中包含ComboBox绑定到ObservableCollection为该行提供的实体的一个.当我向其添加值时ObservableCollection,NullReferenceException抛出a.
有谁知道为什么会这样?这是异常的堆栈跟踪:
at MS.Internal.Data.PropertyPathWorker.DetermineWhetherDBNullIsValid() at MS.Internal.Data.PropertyPathWorker.get_IsDBNullValidForUpdate() at MS.Internal.Data.ClrBindingWorker.get_IsDBNullValidForUpdate() at System.Windows.Data.BindingExpression.ConvertProposedValue(Object value) at System.Windows.Data.BindingExpressionBase.UpdateValue() at System.Windows.Data.BindingExpression.Update(Boolean synchronous) at System.Windows.Data.BindingExpressionBase.Dirty() at System.Windows.Data.BindingExpression.SetValue(DependencyObject d, DependencyProperty dp, Object value) at System.Windows.DependencyObject.SetValueCommon(DependencyProperty dp, Object value, PropertyMetadata metadata, Boolean coerceWithDeferredReference, OperationType operationType, Boolean isInternal) at System.Windows.DependencyObject.SetValue(DependencyProperty dp, Object value) at System.Windows.Controls.Primitives.Selector.UpdatePublicSelectionProperties() at System.Windows.Controls.Primitives.Selector.SelectionChanger.End() at System.Windows.Controls.Primitives.Selector.OnItemsChanged(NotifyCollectionChangedEventArgs e) at System.Windows.Controls.ItemsControl.OnItemCollectionChanged(Object sender, NotifyCollectionChangedEventArgs e) at System.Collections.Specialized.NotifyCollectionChangedEventHandler.Invoke(Object sender, NotifyCollectionChangedEventArgs e) at System.Windows.Data.CollectionView.OnCollectionChanged(NotifyCollectionChangedEventArgs args) at System.Windows.Controls.ItemCollection.System.Windows.IWeakEventListener.ReceiveWeakEvent(Type managerType, Object sender, EventArgs e) …
我无法让我的绑定工作在Detail ListView上.我已粘贴下面的所有MVVM模式代码.请帮忙!!!
我的观点:DirectoryDetailView.cs
<UserControl x:Class="S2.Views.DirectoryDetailView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<ListView Grid.Column="0" ItemsSource="{Binding Path = DirectoryDetails}"
IsSynchronizedWithCurrentItem="True"
SelectedItem="{Binding SelectedDirName, Mode=TwoWay}">
<ListView.View>
<GridView>
<GridViewColumn DisplayMemberBinding="{Binding Path = FileName}"
Header="File Name"/>
</GridView>
</ListView.View>
</ListView>
<ListView Grid.Column="1" Margin="10,0,0,0" ItemsSource="{Binding Path = DirectoryDetails}">
<ListView.View>
<GridView>
<GridViewColumn DisplayMemberBinding="{Binding Path = FileDetails.Length}"
Header="Length"/>
<GridViewColumn DisplayMemberBinding="{Binding Path = FileDetails.LastAccessTime}"
Header="LastAccessTime"/>
</GridView>
</ListView.View>
</ListView>
</Grid>
Run Code Online (Sandbox Code Playgroud)
我的型号:
public class DirectoryModel : INotifyPropertyChanged
{
private string _fileName;
private DateTime _createdTime;
public string FileName
{
get
{
return _fileName; …Run Code Online (Sandbox Code Playgroud) 我的用户界面使用自定义的Buttons:它们包含a Image和a Label.
我Button通过将其内容设置为包含a Image和a 的网格来手动定制单个Label.但是,由于我需要有几个这样的Buttons,不同的图像和标签,我想把这个模式"提取"成可重用的东西.基本上,我只需要一个可重用的对象,有两个属性(Image和Text)我可以设置为Content几个Buttons.
我查看了ContentTemplates,但我不需要自定义控件Button本身的外观,只需要自定义它的内容.
最合适的技术是什么?
wpf ×10
xaml ×4
mvvm ×3
button ×2
data-binding ×2
c# ×1
canvas ×1
command ×1
events ×1
exception ×1
reusability ×1
stackpanel ×1
togglebutton ×1
treeview ×1
wpftoolkit ×1