这是我的情况:
<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发送当前选定的项目?
我需要能够做到这一点:
var getHed = () =>
{
// do stuff
return new { Property1 = value, Property2 = value2, etc...};
};
var anonymousClass = getHed();
Run Code Online (Sandbox Code Playgroud)
但我得到一个错误,表明我需要明确声明getHed.
如何声明Func使得T是我要返回的匿名类型?
如果你好奇我为什么需要这样做,那是因为我使用第三方软件允许自定义代码,但只能在一个方法中使用.这可能变得非常难以管理.我有一个想法,我可以使用匿名方法来帮助保持程序代码的组织.在这种情况下,为了帮助它,我需要一个新类,除了匿名之外我无法定义.
我使用.NET 4为客户创建一个小型客户端服务器应用程序.我应该创建一个实现许多合同的巨型服务(IInvoice,IPurchase,ISalesOrder等),还是应该创建许多服务,在许多端口上运行一个合同?我的问题特别感兴趣的是两种选择的优缺点.另外,回答这个问题的常用方法是什么?
我真正的困境是我没有做出这个决定的经验,而且我对wcf的经验不足以至于我需要帮助理解这个决定的技术含义.
我不明白问题是什么.绑定在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属性?
我该如何进行这项工作?
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 基类的任何线索?
为什么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)
两个问题:
我已经尝试过以下...
我错过了什么!?我假设我犯了一些小疏忽。(这不是我的代码,但现在是我的责任:\
另外,请注意这一事实,使用此样式的地方、按钮的命令和内容都绑定到 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) 我想创建两个app.config文件,让用户通过命令行参数决定使用哪个文件.如何让我的应用程序在我的代码中使用一个.config或另一个?
我正在使用由配置文件设置的设置文件.有两种可能的配置,如果用户可以只输入"> myprogram -live"或"> myprogram -test"并且程序选择要加载的配置文件,则会更容易.谢谢!
如何使用OpenEdge ABL(progress-4gl)代码从目录中删除文件?
我找不到任何代表这个问题的代码示例.我知道如何输出值(路径),以及从值(路径)输入,但是如何完成删除?
c# ×6
wpf ×4
xaml ×4
app-config ×1
architecture ×1
binding ×1
generics ×1
inheritance ×1
listbox ×1
mvvm ×1
openedge ×1
progress-4gl ×1
styles ×1
wcf ×1