我最近遇到了为我的wpf应用程序创建添加和编辑对话框的问题.
我想在代码中做的就是这样.(我主要使用viewmodel第一种方法与mvvm)
调用对话框窗口的ViewModel:
var result = this.uiDialogService.ShowDialog("Dialogwindow Title", dialogwindowVM);
// Do anything with the dialog result
Run Code Online (Sandbox Code Playgroud)
它是如何工作的?
首先,我创建了一个对话服务:
public interface IUIWindowDialogService
{
bool? ShowDialog(string title, object datacontext);
}
public class WpfUIWindowDialogService : IUIWindowDialogService
{
public bool? ShowDialog(string title, object datacontext)
{
var win = new WindowDialog();
win.Title = title;
win.DataContext = datacontext;
return win.ShowDialog();
}
}
Run Code Online (Sandbox Code Playgroud)
WindowDialog是一个特殊而简单的窗口.我需要它来保留我的内容:
<Window x:Class="WindowDialog"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
Title="WindowDialog"
WindowStyle="SingleBorderWindow"
WindowStartupLocation="CenterOwner" SizeToContent="WidthAndHeight">
<ContentPresenter x:Name="DialogPresenter" Content="{Binding .}">
</ContentPresenter>
</Window>
Run Code Online (Sandbox Code Playgroud)
wpf中对话框的问题是dialogresult = true只能在代码中实现.这就是为什么我为我dialogviewmodel实现它的界面.
public class …Run Code Online (Sandbox Code Playgroud) 在VB.NET中会发生这种情况:
Dim x As System.Nullable(Of Decimal) = Nothing
Dim y As System.Nullable(Of Decimal) = Nothing
y = 5
If x <> y Then
Console.WriteLine("true")
Else
Console.WriteLine("false") '' <-- I got this. Why?
End If
Run Code Online (Sandbox Code Playgroud)
但在C#中会发生这种情况:
decimal? x = default(decimal?);
decimal? y = default(decimal?);
y = 5;
if (x != y)
{
Debug.WriteLine("true"); // <-- I got this -- I'm with you, C# :)
}
else
{
Debug.WriteLine("false");
}
Run Code Online (Sandbox Code Playgroud)
为什么会有区别?
我最近发现wpf以两种不同的方式处理INotifyPropertyChanged.我只是想知道是什么原因.
让我们采用正常的双向绑定验证为真.
如果你将一个属性从ui设置为viewmodel就像这样.
但如果你在viewmodel中设置了属性,它会像这样
我安装了VS2015(14.0.24720)更新1.
如果我尝试在VS2015中编辑ico文件,它总是打开画图.如何从Visual Studion中找到旧的ico编辑器?
编辑:帮助/信息列表
Microsoft Visual Studio Enterprise 2015
Version 14.0.24720.00 Update 1
Microsoft .NET Framework
Version 4.6.01055
Installierte Version: Enterprise
Architecture and Modeling Tools 00322-90000-70216-AA711
Microsoft Architecture and Modeling Tools
UML® und Unified Modeling Language™ sind Marken oder eingetragene Marken der Object Management Group, Inc. in den Vereinigten Staaten und anderen Ländern.
Visual Basic 2015 00322-90000-70216-AA711
Microsoft Visual Basic 2015
Visual C# 2015 00322-90000-70216-AA711
Microsoft Visual C# 2015
Visual C++ 2015 00322-90000-70216-AA711
Microsoft Visual C++ 2015
Visual F# …Run Code Online (Sandbox Code Playgroud) how can i achieve this query with Nhibernate Linq?
var l = session.CreateQuery("from Auswahl a where a.Returnkey is not null").List<Auswahl>();
Run Code Online (Sandbox Code Playgroud)
i tried this but it always returns an empty list.
var l = session.Linq<Auswahl>()
.Where(item => !String.IsNullOrEmpty(item.Returnkey))
.Select(item => item)
.ToList();
Run Code Online (Sandbox Code Playgroud) 当我尝试为ComboBox设置BackgroundColor时,它在Windows7中可以正常工作,但在Windows 10中却不能。这是预期的行为还是错误?编辑:我不是说ComboBox弹出窗口,只是普通ComboBox的背景色。
<ComboBox IsEditable="True">
<ComboBox.Style>
<Style TargetType="ComboBox">
<Setter Property="Background" Value="Yellow"></Setter>
</Style>
</ComboBox.Style>
</ComboBox>
Run Code Online (Sandbox Code Playgroud)
编辑:当我使用此代码时,只是为了使所有注释正确:
<ComboBox IsEditable="True" Background="Yellow"/>
Run Code Online (Sandbox Code Playgroud)
一切正常,组合框为黄色。但是,当我想在样式中执行相同操作时-我应该期望它不起作用,因为它的意图是?说真的 这是Styles的目的!
如何动态地将数据与富文本框的文档属性绑定.我在使用c#的Wpf中使用MVVM?
编辑:
我在"codeproject.com/KB/WPF/BindableWPFRichTextBox.aspx"中尝试了这个例子; 但我无法理解那个例子中发生了什么.我是WPF和MVVM的新手.
它在线上抛出错误
try {
var stream = new MemoryStream(Encoding.UTF8.GetBytes(GetDocumentXaml(richTextBox)));
var doc = (FlowDocument)XamlReader.Load(stream);
// Set the document
richTextBox.Document = doc;
}
catch (Exception) { richTextBox.Document = new FlowDocument(); }
Run Code Online (Sandbox Code Playgroud)
错误类似于"根级别的数据无效.第1行,位置1".我给的价值就像"样本文本"
我发现xaml文本应该是这样的
<FlowDocument PagePadding="5,0,5,0" AllowDrop="True" xmlns="schemas.microsoft.com/winfx/2006/xaml/… generated by app back-end</Paragraph>
</FlowDocument>" But how to get this text?
Run Code Online (Sandbox Code Playgroud) 我有以下问题。
我创建了一个 gRpc 服务器(Console App .Net 4.7.2 - 由于 Crystal Reports ,我无法在服务器端执行 Net Core :()和一个客户端(WPF App .Net Core 3.1),我无法在服务器端执行 Net Core ,只要服务器和客户端在我的机器上(Windows 10)。就我将服务器转移到另一台机器(Windows Server 2016)而言,它不再工作了。
这是 RPC 异常:
Status(StatusCode="不可用", Detail="无法连接到所有地址", DebugException="Grpc.Core.Internal.CoreErrorDetailException: {"created":"@1595508082.170000000","description":"无法选择子通道" ,“文件”:“T:\src\github\grpc\workspace_csharp_ext_windows_x64\src\core\ext\filters\client_channel\client_channel.cc”,“file_line”:3948,“referenced_errors”:[{“已创建”:“@ 1595508082.170000000","描述":"无法连接到所有地址","文件":"T:\src\github\grpc\workspace_csharp_ext_windows_x64\src\core\ext\filters\client_channel\lb_policy\pick_first\pick_first.cc" ,“file_line”:394,“grpc_status”:14}]}“)
我尝试了所有的变化。这是我在本地主机上运行的最后一个代码:
服务器:
static void Main(string[] args)
{
var cacert = File.ReadAllText(@"root.crt");
var servercert = File.ReadAllText(@"server.crt");
var serverkey = File.ReadAllText(@"server.key");
var keypair = new KeyCertificatePair(servercert, serverkey);
var sslCredentials = new SslServerCredentials(new List<KeyCertificatePair>() { keypair }, cacert, false);
// Build a server
var …Run Code Online (Sandbox Code Playgroud) 我在现有的数据库中只有VIEW,我想用FHN来获取它们.我尝试通过以下方式映射它:
public class HhstMap : ClassMap<Hhst>
{
public HhstMap()
{
Table("HHST");
ReadOnly();
Id();
Map(x => x.Hkz);
Map(x => x.Kapitel);
Map(x => x.Titel);
Map(x => x.Apl);
Map(x => x.Hhpz);
}
}
Run Code Online (Sandbox Code Playgroud)
但我得到一个错误:无法执行查询[SELECT this_.id as id3_0_,this_.Hkz as Hkz3_0_,this_.Kapitel as Kapitel3_0_,this_.Titel as Titel3_0_,this_.Apl as Apl3_0_,this_.Hhpz as Hhpz3_0_ FROM HHST this_ ]
这是正确的,因为没有ID列,但如何在没有ID的情况下使用Fluent进行映射?
我正在使用 MVVM 并遇到以下问题。我的 TextBox.Text 与 UpdateSourceTrigger=LostFocus 绑定(这就是用户想要的)。我有一个带有 SaveCommand CommandBinding 的按钮 - 这有效。现在我有一个带有 Strg+S 的 KeyBinding,它也执行 SaveCommand。这就是问题所在:当我在文本框中并按 Strg+s 时,更改不在视图模型中。
有没有办法让 MVVM 命令与 KeyBinding 和 TextBox UpdateSourceTrigger=LostFocus 一起工作?
一些代码来检查问题
<Window>
<Window.InputBindings>
<KeyBinding Key="S" Modifiers="Control" Command="{Binding SaveCommand}"></KeyBinding>
</Window.InputBindings>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<TextBox Grid.Row="0" Text="{Binding MyText1, UpdateSourceTrigger=LostFocus}" Width="100"></TextBox>
<Button Grid.Row="1" Content="_Save" Command="{Binding SaveCommand}" IsDefault="True"></Button>
</Grid>
</Window>
public partial class MainWindow : Window
{
private Viewmodel _data;
public MainWindow()
{
_data = new Viewmodel();
InitializeComponent();
this.DataContext = _data;
}
}
public …Run Code Online (Sandbox Code Playgroud) wpf ×5
c# ×4
mvvm ×3
.net ×2
nhibernate ×2
.net-4.0 ×1
binding ×1
combobox ×1
grpc ×1
key-bindings ×1
modal-dialog ×1
null ×1
vb.net ×1
windows-10 ×1