我有一个700w x 300h的WPF应用程序,可以将它拖到我的大屏幕上的任何地方.
我的应用程序执行时:
MessageBox.Show("Sorry, this function is not yet implemented.");
Run Code Online (Sandbox Code Playgroud)
消息框出现在我的屏幕中间,甚至可能在应用程序本身附近.
如何让我的MessageBox出现在我的应用程序中间?
在MSDN文章" 了解WPF中的路由事件和命令"中,它说明了这一点
事件将从源元素向上冒泡(传播)可视树,直到它被处理或到达根元素.
但是,在此示例中,当您单击按钮时,它不会"冒泡可视树"以由父StackPanel事件处理,即单击按钮不会触发任何事件.
为什么不?如果不是这样的话,他们是什么意思"冒泡"?
XAML:
<Window x:Class="TestClickEvents456.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="300" Width="300">
<StackPanel x:Name="TheStackPanel"
Background="Yellow"
MouseDown="TheStackPanel_MouseDown">
<Button x:Name="TheButton"
Margin="10"
Content="Click This"/>
<TextBlock x:Name="TheMessage"
Text="Click the button or the yellow area"/>
</StackPanel>
</Window>
Run Code Online (Sandbox Code Playgroud)
后台代码:
using System.Windows;
using System.Windows.Input;
namespace TestClickEvents456
{
public partial class Window1 : Window
{
public Window1()
{
InitializeComponent();
}
private void TheStackPanel_MouseDown(object sender, MouseButtonEventArgs e)
{
TheMessage.Text = "StackPanel was clicked.";
}
}
}
Run Code Online (Sandbox Code Playgroud) 我正在为WPF 寻找一个简单的时间选择器控件.
http://marlongrech.wordpress.com/2007/11/18/time-picker/
但它有一些问题,例如你不能输入"00",第二个零不会出现.
http://jesseliberty.com/2009/03/28/toolkit-control-%E2%80%93-timepicker/
但它不适用于WPF.
什么是最好的免费WPF控件,允许用户以HH:MM:SS格式输入时间?
在vim当我的光标在第一行时,我可以按:
100dd
删除前100行.
但我怎么删除所有线,除了在最后 100行?
我的XAML文件中有一个文本框:
<TextBox
VerticalScrollBarVisibility="Visible"
AcceptsReturn="True"
Width="400"
Height="100"
Margin="0 0 0 10"
Text="{Binding ItemTypeDefinitionScript}"
HorizontalAlignment="Left"/>
Run Code Online (Sandbox Code Playgroud)
我得到一个字符串,我发送给CreateTable(string)它反过来调用CreateTable(List<string>).
public override void CreateTable(string itemTypeDefinitionScript)
{
CreateTable(itemTypeDefinitionScript.Split(Environment.NewLine.ToCharArray()).ToList<string>());
}
public override void CreateTable(List<string> itemTypeDefinitionArray)
{
Console.WriteLine("test: " + String.Join("|", itemTypeDefinitionArray.ToArray()));
}
Run Code Online (Sandbox Code Playgroud)
问题是字符串显然在每一行的末尾都有'\n\r',所以Split('\n')只得到其中一个,就像Split('\ r')一样,并使用Environment.Newline.ToCharArray ()当我输入这个:
one
two
three
Run Code Online (Sandbox Code Playgroud)
产生这个:
one||two||three
Run Code Online (Sandbox Code Playgroud)
但我当然想要它产生这个:
one|two|three
Run Code Online (Sandbox Code Playgroud)
什么是单行简单地将带有' \n\r'结尾的字符串解析为List<string>?
我想要做的就是确保类Item的子类实现静态方法,并且我希望在编译时检查它以避免运行时错误.
使用静态方法的抽象类似乎不起作用:
错误:无法将静态成员标记为覆盖,虚拟或抽象
public abstract class Item
{
public static abstract Item GetHistoricalItem(int id, DateTime pastDateTime);
}
public class Customer : Item
{
public static override Customer GetHistoricalItem(int id, DateTime pastDateTime)
{
return new Customer();
}
}
public class Address : Item
{
public static override Address GetHistoricalItem(int id, DateTime pastDateTime)
{
return new Address();
}
}
Run Code Online (Sandbox Code Playgroud)
和接口似乎也不起作用:
错误:客户未实现接口成员GetHistoricalItem()
public class Customer : Item, HistoricalItem
{
public static Customer GetHistoricalItem(int id, DateTime pastDateTime)
{ …Run Code Online (Sandbox Code Playgroud) 我可以像这样在TextBlock上单击一下:
private void TextBlock_MouseDown(object sender, MouseButtonEventArgs e)
{
MessageBox.Show("you single-clicked");
}
Run Code Online (Sandbox Code Playgroud)
我可以像这样双击 TextBlock:
private void TextBlock_MouseDown(object sender, MouseButtonEventArgs e)
{
if (e.LeftButton == MouseButtonState.Pressed)
{
if (e.ClickCount == 2)
{
MessageBox.Show("you double-clicked");
}
}
}
Run Code Online (Sandbox Code Playgroud)
但是如何在单个TextBlock上捕获它们并区分它们?
在CSS中,保证金顺序是:右上角左下角
在XAML中,保证金顺序为:左上方左下方
有没有理由为什么WPF团队没有将这与CSS规范对齐?
我试图了解Microsoft目前提供的许多应用程序部署选项.
做了一些研究,发现了数十个令人困惑的术语:
我将我的发现清理成以下七种不同的方法.希望得到反馈:
"使用MSI部署WPF应用程序"(允许大量安装选项)
"使用ClickOnce部署的WPF应用程序":(如果您想要自动更新但在沙箱中运行,则很好)
"XBAP App":.xbap文件的xcopy部署,IE和Firefox会立即显示为网页
我正在寻找完整应用程序的代码,这些应用程序(1)使用MVVM模式,(2)可用于WPF/Silverlight/MVVM初学者.到目前为止我只发现:
还有什么其他的?
优选地使用MVVM但具有完整感觉的较小辅助应用程序或工具,可能具有WPF/Silverlight图形/动画优点等,其不仅显示正在使用的MVVM概念,而且显示在现实世界的已完成应用程序的上下文中
感谢所有提示,我收集了15个MVVM代码示例列表,并在此处发布: