我必须OK
在视图中的Click of Button 上打开一个URL .有人可以告诉你怎么做吗?
我想在某个日期添加日子.我有这样的代码:
DateTime endDate = Convert.ToDateTime(this.txtStartDate.Text);
Int64 addedDays = Convert.ToInt64(txtDaysSupp.Text);
endDate.AddDays(addedDays);
DateTime end = endDate;
this.txtEndDate.Text = end.ToShortDateString();
Run Code Online (Sandbox Code Playgroud)
但是这段代码没有用,几天都没有添加!我正在做的那个愚蠢的错误是什么?
是否有可能具有DataTemplate
组合或继承(类似于样式中的"BasedOn")?有两个我需要的实例.
对于继承的类:我有一个带有几个继承类的基类.我不想在每个派生类中复制基类模板DataTemplate
.
不同的视图:对于同一个类,我想定义一个datatemplate,然后根据需要添加到该模板.防爆.基本模板将显示对象中的数据,然后我想要不同的模板,可以对对象执行不同的操作,同时显示数据(继承基本模板).
我有一个描述GUI部分的WPF xaml文件,我希望特定控件的启用/禁用依赖于其他两个控件.代码看起来像这样:
<ComboBox Name="MyComboBox"
IsEnabled="{Binding ElementName=SomeCheckBox, Path=IsChecked}"/>
Run Code Online (Sandbox Code Playgroud)
但我希望它依赖于另一个复选框,所以类似于:
<ComboBox Name="MyComboBox"
IsEnabled="{Binding ElementName=SomeCheckBox&AnotherCheckbox, Path=IsChecked}"/>
Run Code Online (Sandbox Code Playgroud)
最好的方法是什么?我情不自禁地觉得我错过了一些明显的东西或者错误的方式?
我是否需要在物品消失时取消绑定物品以防止内存泄漏?我想我只是有点担心,如果我重新加载并将新模板应用于控件,并且在该模板中存在与外部元素的绑定,是否可以阻止对模板的控制被垃圾收集?
我在一个Windows forms
应用程序中使用了这个函数
delegate void ParametrizedMethodInvoker5(int arg);
private void log_left_accs(int arg)
{
if (InvokeRequired)
{
Invoke(new ParametrizedMethodInvoker5(log_left_accs), arg);
return;
}
label2.Text = arg.ToString();
}
Run Code Online (Sandbox Code Playgroud)
但在WPF
它不起作用.为什么?
我想移动矩形对象的动画以在x轴上移动它.我是WPF动画的新手,从以下开始:
<Storyboard x:Key="MoveMe">
<DoubleAnimationUsingKeyFrames BeginTime="00:00:00"
Storyboard.TargetName="GroupTileSecond"
Storyboard.TargetProperty="(**Margin.Left**)">
<SplineDoubleKeyFrame KeyTime="00:00:00" Value="**134, 70,0,0**" />
<SplineDoubleKeyFrame KeyTime="00:00:03" Value="**50, 70,0,0**" />
</DoubleAnimationUsingKeyFrames>
</Storyboard>
Run Code Online (Sandbox Code Playgroud)
很明显发现,我不能使用Margin.Left
的Storyboard.TargetProperty
或使用134,70,0,0
的Value属性.
那么,如何在XAML WPF中移动对象.
当我UserControl
在WPF中创建一个新的时,studio会创建一些XAML:
<UserControl x:Class="MOG.Objects.Date.Calender"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<Grid>
</Grid>
</UserControl>
Run Code Online (Sandbox Code Playgroud)
在UserContol
我还可以添加Width属性.DesignWidth
和之间有什么区别Width
?
我希望用户只输入数值TextBox
.
我得到了这段代码:
private void txtType1_KeyPress(object sender, KeyPressEventArgs e)
{
int isNumber = 0;
e.Handled = !int.TryParse(e.KeyChar.ToString(), out isNumber);
}
Run Code Online (Sandbox Code Playgroud)
但我在使用WPF 时没有得到textbox_KeyPress
事件e.KeyChar
.
什么是WPF的解决方案?
Edit:
我做了一个解决方案!
private void txtName_PreviewTextInput(object sender, TextCompositionEventArgs e)
{
CheckIsNumeric(e);
}
private void CheckIsNumeric(TextCompositionEventArgs e)
{
int result;
if(!(int.TryParse(e.Text, out result) || e.Text == "."))
{
e.Handled = true;
}
}
Run Code Online (Sandbox Code Playgroud) 以下代码工作正常.
<Window.Triggers>
<EventTrigger RoutedEvent="Window.Loaded">
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Duration="0:0:.8" Storyboard.TargetProperty="Left" From="1920" To="0" AccelerationRatio=".1"/>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</Window.Triggers>
Run Code Online (Sandbox Code Playgroud)
但在这方面From
,To
价值观是静态的.我需要根据系统分辨率动态传递值.所以我需要在后面的代码中创建它.有可能吗?
如何将其转换为代码隐藏?