小编Dav*_*mer的帖子

WPF:在不知道项目的情况下更改ComboBox的FontSize

我想在wpf中设置FontSize一些ComboBoxes.但我找到的唯一解决方案是设置FontSize特定的ComboBoxItems.但这些项目是动态添加的(所以我ItemsChanged每次都可以收听并设置样式,但这非常难看).有没有办法设置一般的FontSize所有项目ComboBox

EDIT1:ComboBox自身也在动态地添加代码上课.

编辑2:按照你的答案,它必须是这样的:

<Style TargetType="ComboBox" x:Key="MyComboBox"">
    <Setter Property="ItemContainerStyle" Value="{DynamicResource MyComboItemStyle}"/>
</Style>
<Style x:Key="MyComboItemStyle" TargetType="{x:Type ComboBoxItem}">
    <Setter Property="FontSize" Value="14"/>
</Style>
Run Code Online (Sandbox Code Playgroud)

但它也没有效果!

编辑3:这是我添加项目的方式:

string[] strEnums = //Some dynamic magic;
foreach (string str in strEnums)
{
    (input as ComboBox).Items.Add(strEnum);
}
Run Code Online (Sandbox Code Playgroud)

EDIT4:这是组合框的初始化:

input = new ComboBox();
input.SetResourceReference(ComboBox.StyleProperty, "MyComboBox");
Run Code Online (Sandbox Code Playgroud)

就这样!

wpf combobox styles font-size

2
推荐指数
2
解决办法
8693
查看次数

ItemsControl包装窗口内的内容

ItemsControl在WPF中使用了一个窗口.itemscontrol与集合绑定,集合是一组视图模型(用户控件).我的问题 - 由于集合中的许多视图模型,视图超出了当前窗口.我用滚动条尝试了很多东西来处理它但没用.有什么建议?问题是如何在窗口中包含itemscontrol(滚动)?

下面的XAML

<Window x:Class="WpfApplicationTest.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
     xmlns:app="clr-namespace:WpfApplicationTest"
    Title="MainWindow" Height="350" Width="525">   
  <Grid Height="Auto">
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto"/>
        <RowDefinition Height="30"/>
    </Grid.RowDefinitions>
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="Auto"/>
    </Grid.ColumnDefinitions>
    <ItemsControl Grid.Row="0" Grid.Column="0" ItemsSource="{Binding UserControlCollection}" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"/>           
    <StackPanel Grid.Row="1" Grid.Column="0" Orientation="Horizontal" VerticalAlignment="Bottom">
        <Button Content="OK" Width="100" Margin="3" />
        <Button Content="Cancel" Width="100" Margin="3" />
    </StackPanel>
</Grid>
Run Code Online (Sandbox Code Playgroud)

wpf user-controls itemscontrol mvvm itemsource

2
推荐指数
1
解决办法
986
查看次数

基于对象中的枚举字段的xaml样式

我有这样的对象集合:

public enum ObjectType
{
   Type1,
   Type2
}

public class MyObject
{
   ...
   public ObjectType ObjType;
   public string Header;
   ...
}
Run Code Online (Sandbox Code Playgroud)

我从示例应用程序获得的样式之一是:

    <Style TargetType="{x:Type inf:MyObject}">
        <Setter Property="Header" Value="{Binding Header}" />
    </Style>
Run Code Online (Sandbox Code Playgroud)

如何创建受ObjectType枚举字段约束的单独样式?IE对于ObjType设置为Type1 vs Type2的MyObject具有单独的样式?

我的字段确实实现了INotifyPropertyChanged,这只是一些简单的示例代码

谢谢

c# wpf enums xaml styles

2
推荐指数
1
解决办法
1875
查看次数

对于WPF中的UIElements(按钮),如何将"isfocusable"属性设置为false?

我试图将属性设置UIElement为不可聚焦,但似乎没有按钮的isfocusable属性.有没有人有什么建议?谢谢 :)

wpf focus uielement

2
推荐指数
1
解决办法
1858
查看次数

如何删除Silverlight单元测试框架的5s延迟

我使用Silverlight单元测试框架,它运行良好.

但是每次我启动测试时,我都要等待5秒钟或者单击" 否,运行所有测试 "按钮.

有没有办法跳过我不需要的这一步?

testing silverlight unit-testing silverlight-toolkit

2
推荐指数
1
解决办法
150
查看次数

如果在ListView中未选择任何项目,如何禁用按钮

ListView在UserControl中有一个Contained我想在UserControl中没有选择任何项目时禁用一个按钮,这是正确的方法吗?到目前为止,它没有禁用,它只是一直保持启用状态.我已经包含了xaml代码.

searchAccountUserControl是xaml中的UserControl名称属性.AccountListView是ListViewuserControl xaml中的name属性.

<Button Content="Debit" IsEnabled="true" HorizontalAlignment="Left" Margin="18,175,0,0" Name="DebitButton" Width="128" Grid.Column="1" Height="32" VerticalAlignment="Top" Click="DebitButton_Click">
        <Button.Style>
            <Style TargetType="Button">
                <Style.Triggers>
                    <DataTrigger Binding="{Binding ElementName=searchAccountUserControl.AccountListView, Path=SelectedValue}" Value="{x:Null}" >
                        <Setter Property="Button.IsEnabled" Value="false"/>
                    </DataTrigger>
                </Style.Triggers>
            </Style>
        </Button.Style>
    </Button>
Run Code Online (Sandbox Code Playgroud)

谢谢.

最后我用过:

在我的ViewModel中:

private bool _isSelected;
public bool IsSelected { get { return _isSelected; } 
set { _isSelected = _account.View.CurrentItem != null;       
PropertyChanged.SetPropertyAndRaiseEvent(this, ref _isSelected, value,  
ReflectionUtility.GetPropertyName(() => IsSelected)); } } 
Run Code Online (Sandbox Code Playgroud)

然后在xaml中使用isEnabled ="{Binding Path = IsSelected}".

c# wpf xaml user-controls listview

2
推荐指数
1
解决办法
1万
查看次数

JOptionPane并从输入中获取文本

我创建了一个打开的按钮JOptionPane.它允许用户输入string..>> String str = JOptionPane.showInputDialog 如何获取用户输入到joptionpane的文本并使用它来搜索userobjects?

非常感谢

java string swing joptionpane

2
推荐指数
1
解决办法
2万
查看次数

如何在WPF中为自定义TextBox控件指定CornerRadius?

我用以下代码创建了自定义ctextbox.但我无法为此提供圆角边界.

public class FilteredTextBox : TextBox
{


    public FilteredTextBox()
        : base()
    {
        IsNumeric = false;
        IsRegex = false;
        IsRequired = false;
        ErrorMsg = "";
        RegexText = "";
        HorizontalAlignment = HorizontalAlignment.Stretch;
        Margin = new Thickness(0);
        BorderThickness = new Thickness(1);
        var border = new Border {CornerRadius = new CornerRadius(4)};
     }
   }
Run Code Online (Sandbox Code Playgroud)

请指导我这个?

c# wpf user-controls styles textbox

2
推荐指数
1
解决办法
5466
查看次数

从其他窗口获取MainWindow框架

所以我在这个窗口的某个窗口2中我尝试通过创建Mainwindow的对象来获取在MainWindow.xaml中定义的框架,并尝试导航到页面,但程序给出了"用户代码未触发的空引用异常"

我用了:

 public Window2()
  {
   }

 myfunction()
 {
 MainWindow rootwindow = new MainWindow();
  rootwindow.myframe.Navigate( new Page1());
  }
Run Code Online (Sandbox Code Playgroud)

wpf user-controls wpf-controls

2
推荐指数
1
解决办法
6421
查看次数

初始DataGrid排序

我有一个包含WPF工具包的用户控件DataGrid.此控件用于我的应用程序中的许多不同位置.网格不知道将显示的数据类型.有没有办法最初按第一列按升序对网格进行排序,无论网格填充什么数据?我不认为我可以使用a,CollectionViewSource因为我不知道PropertyName绑定到第一列的属性.

wpf user-controls wpfdatagrid

2
推荐指数
1
解决办法
7593
查看次数