小编Pri*_*nes的帖子

如何将listbox selecteditem作为命令参数传递给按钮?

这是我的情况:

<ListBox ItemsSource="{Binding Path=AvailableUsers}">
    <ListBox.ItemTemplate>
        <DataTemplate>
            <TextBlock Text="{Binding Path=Id}"/>
        </DataTemplate>
    </ListBox.ItemTemplate>
</ListBox>
<Button Command="{Binding Path=Load}" CommandParameter={???? What goes here ????}/>
Run Code Online (Sandbox Code Playgroud)

我想要的是传递ListBox中当前选中的Id.我有幕后的viewmodel,基本上是这样的:

public class ViewModel : DependencyObject
{
    ICommand Load { get; set; }

    // dependency property but I didn't bother to write it out like one
    List<User> AvailableUsers { get; set}
}
Run Code Online (Sandbox Code Playgroud)

如何使用xaml发送当前选定的项目?

wpf xaml binding listbox mvvm

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

如何使用匿名返回类型声明Func?

我需要能够做到这一点:

var getHed = () => 
{
    // do stuff
    return new { Property1 = value, Property2 = value2, etc...};
};

var anonymousClass = getHed();
Run Code Online (Sandbox Code Playgroud)

但我得到一个错误,表明我需要明确声明getHed.

如何声明Func使得T是我要返回的匿名类型?

如果你好奇我为什么需要这样做,那是因为我使用第三方软件允许自定义代码,但只能在一个方法中使用.这可能变得非常难以管理.我有一个想法,我可以使用匿名方法来帮助保持程序代码的组织.在这种情况下,为了帮助它,我需要一个新类,除了匿名之外我无法定义.

c# anonymous-types anonymous-function

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

wcf决定:一个服务多个合同或许多服务

我使用.NET 4为客户创建一个小型客户端服务器应用程序.我应该创建一个实现许多合同的巨型服务(IInvoice,IPurchase,ISalesOrder等),还是应该创建许多服务,在许多端口上运行一个合同?我的问题特别感兴趣的是两种选择的优缺点.另外,回答这个问题的常用方法是什么?

我真正的困境是我没有做出这个决定的经验,而且我对wcf的经验不足以至于我需要帮助理解这个决定的技术含义.

c# architecture wcf

8
推荐指数
1
解决办法
4557
查看次数

WPF DataGridTextColumn绑定不接受小数

我不明白问题是什么.绑定在Decimal属性上.这是XAML:

<DataGridTextColumn Header="Price" Binding="{Binding Price, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged} Width="*"/>
Run Code Online (Sandbox Code Playgroud)

我字面上不能输入'.' 字符.为什么它会阻止我输入那个字符,我怎么告诉它让我这样做.

我试着像这样做一个字符串格式:

<DataGridTextColumn Header="Price" Binding="{Binding Price, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, StringFormat={}{0:n2}} Width="*"/>
Run Code Online (Sandbox Code Playgroud)

但这并没有解决我的问题,因为它所做的就是将".00"附加到我输入的任何内容的末尾.

我只需要输入句号即可.

更新:

我被引导到这里.我删除了UpdateSourceTrigger属性,这使我可以输入'.'.我没有安装4.5 Beta,我的本地化设置是正确的.所以现在我的问题是如何让DataGridTextColumn允许我输入'.' 是否设置了UpdateSourceTrigger属性?

c# wpf xaml datagridtextcolumn

8
推荐指数
1
解决办法
3097
查看次数

如何在 wpf 中使用通用基类而不是窗口?

我该如何进行这项工作?

public partial class MyWindow : View<MyViewModel>
{
}
Run Code Online (Sandbox Code Playgroud)

其中视图定义为

public class View<T> : Window where T : IViewModel, new()
{
}
Run Code Online (Sandbox Code Playgroud)

XAML:

<local:View
x:Class="Project.MyWindow"
x:TypeArguments="ViewModels:MyViewModel"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity" 
xmlns:ei="http://schemas.microsoft.com/expression/2010/interactions" 
xmlns:ViewModels="clr-namespace:Mynamespace.ViewModels;assembly=Mynamespace.ViewModels"
xmlns:local="clr-namespace:Project"
>
Run Code Online (Sandbox Code Playgroud)

我收到此错误...命名空间 Project 中不存在名称 View...当然它确实存在。

我得到这个错误,这真的让我很困惑...“ http://schemas.microsoft.com/winfx/2006/xaml ”命名空间中不存在属性“TypeArguments” ...当然它确实存在。

关于如何在 wpf 中使用泛型作为 Windows 基类的任何线索?

generics wpf inheritance xaml

5
推荐指数
1
解决办法
6783
查看次数

DbSet <T> .Where(where).ToList() - 为什么SQL不包含where子句?

为什么EF 6使用以下代码查询数据库中的所有记录?

    public virtual List<T> Find(Func<T, bool> where = null)
    {
        _db.Configuration.LazyLoadingEnabled = false;
        if (where == null) throw new NullReferenceException("The 'where' parameter of the Repository.Find() method is null.");    
        return _dbSet.Where(where).ToList();
    }
Run Code Online (Sandbox Code Playgroud)

产生以下输出

SELECT
    [Extent1].[Id] AS [Id],
    [Extent1].[Sequence] AS [Sequence],
    [Extent1].[Description] AS [Description],
    [Extent1].[Instructions] AS [Instructions],
    [Extent1].[WorkCenterOperationId] AS [WorkCenterOperationId],
    [Extent1].[JobId] AS [JobId],
    [Extent1].[JobAssemblyId] AS [JobAssemblyId],
    [Extent1].[RowVersion] AS [RowVersion]
    FROM [dbo].[JobOperations] AS [Extent1]
Run Code Online (Sandbox Code Playgroud)

两个问题:

  1. 为什么不使用where语句执行查询?
  2. 如何使用where语句执行查询?

c# entity-framework entity-framework-6

4
推荐指数
1
解决办法
804
查看次数

按钮的 ControlTemplate 的 ContentPresenter 的 Textblock 的前景没有改变

我已经尝试过以下...

  1. 设置按钮的 TextBlock.Foreground。
  2. 设置 contentpresenter 的 TextBlock.Foreground。
  3. 设置 IsMouseOver 触发器,如下所示。
  4. 设置不带目标名称的 IsMouseOver 触发器(假设它按下按钮)。
  5. 在我尝试过 TextBlock.Foreground 的所有地方,我都尝试过 TextElement.Foreground。

我错过了什么!?我假设我犯了一些小疏忽。(这不是我的代码,但现在是我的责任:\

另外,请注意这一事实,使用此样式的地方、按钮的命令和内容都绑定到 mvvm 样式视图模型。

    <Style x:Key="ButtonStyle2" TargetType="{x:Type Button}">
        <Setter Property="FocusVisualStyle" Value="{StaticResource FocusVisual}"/>
        <Setter Property="Background" Value="{StaticResource Button.Static.Background}"/>
        <Setter Property="BorderBrush" Value="{StaticResource Button.Static.Border}"/>
        <Setter Property="BorderThickness" Value="1"/>
        <Setter Property="HorizontalContentAlignment" Value="Center"/>
        <Setter Property="VerticalContentAlignment" Value="Center"/>
        <Setter Property="Padding" Value="1"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type Button}">
                    <Border x:Name="border" SnapsToDevicePixels="true">
                        <Border.Background>
                            <SolidColorBrush Color="{StaticResource Color2}"/>
                        </Border.Background>
                        <ContentPresenter x:Name="contentPresenter" Focusable="False" TextElement.Foreground="{TemplateBinding Foreground}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}" RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
                    </Border>
                    <ControlTemplate.Triggers>
                        <Trigger …
Run Code Online (Sandbox Code Playgroud)

c# wpf xaml styles

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

如何让我的应用程序在两个app.config文件之间进行选择?

我想创建两个app.config文件,让用户通过命令行参数决定使用哪个文件.如何让我的应用程序在我的代码中使用一个.config或另一个?

我正在使用由配置文件设置的设置文件.有两种可能的配置,如果用户可以只输入"> myprogram -live"或"> myprogram -test"并且程序选择要加载的配置文件,则会更容易.谢谢!

c# configuration app-config

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

进度4gl OpenEdge abl从目录中删除文件

如何使用OpenEdge ABL(progress-4gl)代码从目录中删除文件?

我找不到任何代表这个问题的代码示例.我知道如何输出值(路径),以及从值(路径)输入,但是如何完成删除?

progress-4gl openedge

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