小编Mik*_*e B的帖子

什么时候应该在WPF 4.0中使用SnapsToDevicePixels?

任何人都可以建议何时SnapsToDevicePixels在WPF 4.0中使用?

它是否应该仅在有问题的情况下偶尔使用,在整个应用程序中,只在某些控件或什么?

.net wpf snapstodevicepixels

56
推荐指数
3
解决办法
3万
查看次数

为什么WPF Style在ToolTip中显示验证错误为TextBox工作但对ComboBox失败?

我使用一个典型的样式来显示验证错误作为IErrorDataInfo的工具提示,如下所示,它可以正常工作.

    <Style TargetType="{x:Type TextBox}">
        <Style.Triggers>
            <Trigger Property="Validation.HasError" Value="true">
                <Setter Property="ToolTip"
                Value="{Binding RelativeSource={RelativeSource Self},
            Path=(Validation.Errors)[0].ErrorContent}"/>
            </Trigger>
        </Style.Triggers>
    </Style>
Run Code Online (Sandbox Code Playgroud)

但是当我尝试为这样的ComboBox做同样的事情时,它失败了

    <Style TargetType="{x:Type ComboBox}">
        <Style.Triggers>
            <Trigger Property="Validation.HasError" Value="true">
                <Setter Property="ToolTip"
                Value="{Binding RelativeSource={RelativeSource Self},
            Path=(Validation.Errors)[0].ErrorContent}"/>
            </Trigger>
        </Style.Triggers>
    </Style>
Run Code Online (Sandbox Code Playgroud)

我在输出窗口中得到的错误是:

System.Windows.Data错误:17:无法从'(Validation.Errors)'获取'Item []'值(类型'ValidationError')(类型'ReadOnlyObservableCollection`1').BindingExpression:路径=(0)[0] .ErrorContent; DataItem ='ComboBox'(Name ='ownerComboBox'); target元素是'ComboBox'(Name ='ownerComboBox'); target属性是'ToolTip'(类型'Object')ArgumentOutOfRangeException:'System.ArgumentOutOfRangeException:指定的参数超出了有效值的范围.参数名称:index'

奇怪的是,如果我更改任何ComboBox值,它也会尝试在关闭窗口时进行无效的数据库更改(这也是发生绑定错误时)!

无法将值NULL插入列'EmpFirstName',表'OITaskManager.dbo.Employees'; 列不允许空值.INSERT失败.该语句已终止.

简单地通过评论风格完美的每一个作品.我该如何解决?

万一有人需要它,其中一个comboBox'xaml如下:

<ComboBox ItemsSource="{Binding Path=Employees}" 
                  SelectedValuePath="EmpID"                       
                  SelectedValue="{Binding Path=SelectedIssue.Employee2.EmpID,
                     Mode=OneWay, ValidatesOnDataErrors=True}" 
                  ItemTemplate="{StaticResource LastNameFirstComboBoxTemplate}"
                  Height="28" Name="ownerComboBox" Width="120" Margin="2" 
                  SelectionChanged="ownerComboBox_SelectionChanged" />


<DataTemplate x:Key="LastNameFirstComboBoxTemplate">
    <TextBlock> 
         <TextBlock.Text> 
             <MultiBinding StringFormat="{}{1}, {0}" > 
                   <Binding Path="EmpFirstName" /> 
                   <Binding Path="EmpLastName" /> 
             </MultiBinding> …
Run Code Online (Sandbox Code Playgroud)

c# data-binding validation wpf styles

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

如何将通用项添加到绑定到WPF中的集合的ComboBox

我在WPF应用程序中有一个ComboBox,它绑定到C#ViewModel类中的Department对象的ObservableCollection.我想使用组合框按部门过滤另一个集合(现在它确实适用于此)问题是我想在列表顶部添加一个额外的选项"全部".有没有正确的方法来做到这一点.制作假部门在很多方面都是错误的.

ComboBox

<ComboBox ItemsSource="{Binding Path=Departments}" 
          SelectedValue="{Binding Path=DepartmentToShow , Mode=TwoWay}" />
Run Code Online (Sandbox Code Playgroud)

c# wpf combobox mvvm

16
推荐指数
1
解决办法
4852
查看次数

为什么此flowdocument表始终打印2列

我的WPF应用程序中有一个ListView,它绑定到要执行的任务集合(待办事项列表).我希望用户能够打印他们的列表,并根据MSDN指南创建以下代码.(这是我第一次涉足印刷业)

public FlowDocument GetPrintDocument()
{
    FlowDocument flowDoc = new FlowDocument();
    Table table = new Table();

    int numColumns = 3;

    flowDoc.Blocks.Add(table);

    for(int x=0;x<numColumns;x++)
    {
        table.Columns.Add(new TableColumn());
    }
    GridLengthConverter glc = new GridLengthConverter();
    table.Columns[0].Width = (GridLength)glc.ConvertFromString("300");
    table.Columns[1].Width = (GridLength)glc.ConvertFromString("50");
    table.Columns[2].Width = (GridLength)glc.ConvertFromString("50");

    table.RowGroups.Add(new TableRowGroup());

    table.RowGroups[0].Rows.Add(new TableRow());
    // store current working row for reference
    TableRow currentRow = table.RowGroups[0].Rows[0];

    currentRow.FontSize = 16;
    currentRow.FontWeight = FontWeights.Bold;

    currentRow.Cells.Add(new TableCell(new Paragraph(new Run("Subject"))));
    currentRow.Cells.Add(new TableCell(new Paragraph(new Run("Due Date"))));
    currentRow.Cells.Add(new TableCell(new Paragraph(new Run("Urgency"))));

    for (int i = 1; i …
Run Code Online (Sandbox Code Playgroud)

c# printing wpf flowdocument

15
推荐指数
1
解决办法
5234
查看次数

以编程方式在Linq中使用条件

我刚刚阅读了最近关于在Linq中使用条件的问题,它让我想起了一个我无法解决的问题.在以编程方式构建Linq to SQL查询时,如果在运行时之前不知道条件数,那么如何才能完成此操作?

例如,在下面的代码中,第一个子句创建一个IQueryable,如果执行它,将选择数据库中的所有任务(称为问题),第二个子句将优化为仅分配给一个部门的问题(如果已在一个部门中选择了一个) combobox(将其选中的项目绑定到departmentToShow属性).

我怎么能使用selectedItems集合呢?

IQueryable<Issue> issuesQuery;

// Will select all tasks
issuesQuery = from i in db.Issues
              orderby i.IssDueDate, i.IssUrgency
              select i;

// Filters out all other Departments if one is selected
   if (departmentToShow != "All")
   {
        issuesQuery = from i in issuesQuery
                      where i.IssDepartment == departmentToShow
                      select i;
    }
Run Code Online (Sandbox Code Playgroud)

顺便说一下,上面的代码被简化了,在实际代码中有大约十几个子句根据用户搜索和过滤器设置细化查询.

c# linq linq-to-sql

7
推荐指数
1
解决办法
1677
查看次数

如何在WPF ComboBox中使用MultiBinding

这让我坚持不懈!

ComboBox习惯过滤员工的查询工作正常,但只显示员工的名字.我想使用a MultiValueConverter来显示员工的全名(如果我们没有2个Mikes和2个Daves,那就不那么紧急了)

下面是我的工作代码和IMultiValueConverter类(为了简洁,修剪了不必要的格式).我已经尝试了一切我能想到的让MultiConverter工作但我没有运气.

<ComboBox ItemsSource="{Binding Path=EmployeesFilter}" 
                       DisplayMemberPath="EmpFirstName"
                       SelectedValue="{Binding Path=EmployeeToShow, Mode=TwoWay}"/>
Run Code Online (Sandbox Code Playgroud)

它绑定的ViewModel属性:

// This collection is used to populate the Employee Filter ComboBox
private ObservableCollection<Employee> employeesFilter;
public ObservableCollection<Employee> EmployeesFilter
{
    get {
            return employeesFilter;
        }
    set {
        if (employeesFilter != value)
        {
            employeesFilter = value;
            OnPropertyChanged("EmployeesFilter");
        }
    }
}

// This property is TwoWay bound to the EmployeeFilters SelectedValue
private Employee employeeToShow;
public Employee EmployeeToShow
{
    get {
            return employeeToShow;
        }
    set {
        if (employeeToShow …
Run Code Online (Sandbox Code Playgroud)

c# data-binding wpf xaml ivalueconverter

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

如何使用VSTO 2010 for Excel按名称显示工作表

我从未使用过VSTO,我发现很难找到2010年的学习辅助工具.

我的需求很简单,我有一个包含42个工作表的业务工作簿(我原先猜测了20个,但在计数后发现了一个令人惊讶的数字).我想使用VSTO添加功能区(这部分很简单),以便员工轻松浏览大量页面.我似乎无法找到c#代码来显示我可以简单地添加到按钮的单击事件的特定工作表(最好是通过名称).

谢谢

c# excel vsto

6
推荐指数
1
解决办法
5454
查看次数