当我单击最大化按钮时,窗口最大化但控件未按比例调整大小.使控件调整大小的最佳方法是什么?我正在使用MVVM.
这是我的代码.
<Window x:Class="DataTransfer.View.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Icon="/DataTransfer;component/View/Images/ms_msnexplore.gif"
ResizeMode="CanResizeWithGrip"
Title="Window1" Height="500" Width="600">
<!--Style="{DynamicResource OfficeStyle}"-->
<Window.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<!--<ResourceDictionary Source="/DataTransfer;component/View/WindowBase.xaml" />-->
<!--<ResourceDictionary Source="/DataTransfer;component/Themes/WPFThemes/CalendarResource.xaml" />-->
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Window.Resources>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width ="*" />
</Grid.ColumnDefinitions>
<Button Content="Button" HorizontalAlignment="Left" Margin="52,28,0,0" VerticalAlignment="Top" Width="75" Height="22" />
<DatePicker Name="dp" HorizontalAlignment="Left" Margin="175,25,0,0" VerticalAlignment="Top" Width="123" Text="aaa" GotFocus="DateGotFocused" LostFocus="OnLeaveArchiveDate"/>
<Calendar HorizontalAlignment="Left" Margin="47,162,0,0" VerticalAlignment="Top"/>
<TextBox Name="t1" HorizontalAlignment="Left" Height="23" Margin="337,23,0,0" TextWrapping="Wrap" Text="TextBox" VerticalAlignment="Top" Width="120" LostFocus="LeaveField" />
<RadioButton Content="RadioButton" HorizontalAlignment="Left" Margin="88,92,0,0" VerticalAlignment="Top"/>
<CheckBox Content="CheckBox" HorizontalAlignment="Left" Margin="252,96,0,0" VerticalAlignment="Top"/>
<ComboBox …Run Code Online (Sandbox Code Playgroud) C#和.Net 2.0问题(WinForms)
我选择了一组项目,ComboBox而没有选择它们.我想在那种情况下在组合" 请选择项目 " 上显示一个字符串.
当前实现只是在索引0上添加了带有此类文本的空项,并在用户选择以下项之一时将其删除.不幸的是,空项目也显示在下拉列表中.如何避免这种情况或以其他方式 - 有什么方法可以ComboBox在没有选择项目时显示自定义文本?
当ComboBoxStyle设置为DropDown(ComboBox可编辑)时,下面的答案工作.是否有可能在ComboBoxStyle设置时执行此操作DropDownList?
我想在组合框中显示默认文本.例如,"选择一个人"消息.你能帮帮我吗?
请注意我正在使用domaincontext的数据绑定
谢谢 !!
如何在属性不为null时在WPF中触发操作?当为null时,这是一个有效的解决方案:
<Style.Triggers>
<DataTrigger Binding="{Binding}" Value="{x:Null}">
<Setter Property="Background" Value="Yellow" />
</DataTrigger>
</Style.Triggers>
Run Code Online (Sandbox Code Playgroud)
我知道你不能"扭转"这种情况并做你需要的事情,但想知道
我目前有一个combobox必然的dictionary.我要做的是在其中有一个默认项目combobox,例如"请选择一个项目...",当用户实际点击combobox选择项目时,该项目就会消失.
我在这个网站上看到过类似的问题,但似乎无法让任何解决方案适合我.我唯一的运气就是把它放在我的xaml组合框代码中:
<IsEditable="True" IsReadOnly="True" Text="Please select an item..."/>
Run Code Online (Sandbox Code Playgroud)
但这当然会改变它的外观,combobox我不希望它看起来像是可编辑的.
我的代码背后:
private Dictionary<string, string> imageTypes = new Dictionary<string, string>();
public MainWindow()
{
InitializeComponent();
AddImage_Types();
}
public void AddImage_Types()
{
imageTypes.Add("*.png", Png);
imageTypes.Add("*.jpg *.jpeg *jfif", Jpg);
}
public Dictionary<string, string> ImageTypes
{
get
{
return imageTypes;
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的组合框的xaml:
<ComboBox Name="imageCB"
ItemsSource="{Binding RelativeSource={RelativeSource AncestorType=Window, Mode=FindAncestor}, Path=ImageTypes}"
SelectedValuePath="Value"
DisplayMemberPath="Key" >
</ComboBox>
Run Code Online (Sandbox Code Playgroud)
我尝试过使用触发器和样式,就像这个答案:https://stackoverflow.com/a/16782339/2480598
我确信它很简单,但我似乎无法得到它.
注意:默认项目,我的意思是当窗口加载时,一些文本已经显示在组合框中,如"请选择项目...".当用户单击组合框以从下拉列表中选择项目时,这将消失.
在 WPF ComboBox 中,我需要能够显示绑定的ItemsSource集合中不存在的SelectedValue。
我已经进行了大量的搜索,到目前为止我找到的唯一解决方案是绑定到Text属性并设置IsEditable ="True"。我确实在应用程序的另一部分使用了它,但这在这里不起作用,因为我不能冒用户提供无效数据的风险。
在 XAML 中,ItemsSource绑定到可用 WorkEffort 的 ObservableCollection。该列表可能会随着时间的推移而发生变化,项目会从列表中删除。SelectedValue绑定到数据网格上的 SelectedItem 属性 Title.WorkEffort。标题是一项单独的任务或变更,分配有工作量。一旦分配给标题,即使工作不再活跃,它也不应该改变。
XAML:
<ComboBox ItemsSource="{Binding Path=WorkEfforts}"
SelectedValue="{Binding Path=Title.WorkEffort}"
DisplayMemberPath="WorkEffortString"
SelectedValuePath="WorkEffortString"
IsEnabled="{Path=EditMode}"/>
Run Code Online (Sandbox Code Playgroud)
C# 代码:
ObservableCollection<WorkEffort> WorkEfforts = client.GetWorkEfforts();// Gets a list of all active work efforts from database
public class WorkEffort
{
public int WorkEffortID { get; set; }
public string WorkEffortString { get; set; }
public string ChargeNumber { get; set; }
}
ChangeTitle Title { …Run Code Online (Sandbox Code Playgroud)