在我们使用WPF for UI构建的(相当大的)LOB应用程序中,我们有许多包含相同类型的数据子对象的视图模型.例如,有很多地址
public class AddressViewModel : INotifyPropertyChanged
{
public string City {...}
public string ZipCode {...}
public string Address {...}
public string Number {...}
// INPC logic omitted
}
Run Code Online (Sandbox Code Playgroud)
分散在业务对象中:
public class CustomerViewModel : INotifyPropertyChanged
{
public string Name {...}
public AddressViewModel BillingAddress {...}
public AddressViewModel DeliveryAddress {...}
/*
...
*/
}
Run Code Online (Sandbox Code Playgroud)
是否可以构建一个可重用的自定义用户控件,我们可以绑定到任何地址子对象?
在用于编辑客户详细信息的视图(可能是另一个自定义用户控件)中,我们希望像这样放置一个自定义控件
<UserControl x:Class="OurApp.View.AddressEditor"
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>
<TextBox x:Name="ZipCode" Text="{Binding Path=ZipCode, UpdateSourceTrigger = PropertyChanged}" Validation.ErrorTemplate="{x:Null}" HorizontalAlignment="Left" Height="23" Margin="10,19,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="120" /> …Run Code Online (Sandbox Code Playgroud) 我有我的自定义 3D 模型类 (Model),它包含 Visual3D 元素和一个Storyboard(sb) 来保存与该模型相关的动画。我正在尝试使用 旋转 Visual3D 元素,Storyboard但不幸的是它不起作用。
这是代码片段
public void AnimationRotate(Model model, double duration, double startTime, RepeatBehavior behaviour)
{
//Rotate transform 3D
RotateTransform3D rotateTransform = new RotateTransform3D();
//assign transform to the model
model.Visual3D.Transform = Transform3DHelper.CombineTransform(model.Visual3D.Transform, rotateTransform);
//define the rotation axis
AxisAngleRotation3D rotateAxis = new AxisAngleRotation3D(new Vector3D(0, 0, 1), 180);
//create 3D rotation animation
Rotation3DAnimation rotateAnimation = new Rotation3DAnimation(rotateAxis, TimeSpan.FromSeconds(0.5));
//rotation behaviour
rotateAnimation.RepeatBehavior = behaviour;
//start animation from time
rotateAnimation.BeginTime = TimeSpan.FromSeconds(startTime);
//begin animation …Run Code Online (Sandbox Code Playgroud) 我正在尝试找到一种在UIElement上设置Background属性的通用方法.
我运气不好......
这是我到目前为止(尝试使用反射来获取BackgroundProperty).
Action<UIElement> setTheBrushMethod = (UIElement x) =>
{
var brush = new SolidColorBrush(Colors.Yellow);
var whatever = x.GetType().GetField("BackgroundProperty");
var val = whatever.GetValue(null);
((UIElement)x).SetValue(val as DependencyProperty, brush);
brush.BeginAnimation(SolidColorBrush.ColorProperty, new ColorAnimation(Colors.White, TimeSpan.FromSeconds(3)));
};
setTheBrushMethod(sender as UIElement);
Run Code Online (Sandbox Code Playgroud)
事情是......它适用于类似TextBlock的东西,但不适用于像StackPanel或Button这样的东西.
对于StackPanel或Button,"whatever"最终为null.
我也觉得应该有一个简单的方法来一般设置背景.我错过了吗?
后台似乎只在System.Windows.Controls.Control上可用,但我无法转换为.
我很难解决我的问题,我真的很生气.
这里的想法是:我有两个ListView元素,当元素从第一个列表下降到第二个列表时,我需要打开一个对话框,但我需要删除元素中的信息和添加的元素以填充对话框.
问题是,我甚至无法获得正确的基本功能 - 这就是打开对话框.
我将从头到尾学习D&D技术,但我很快就需要一种方法来至少调用对话.
在编写和删除一些代码之后,我唯一剩下的就是以下内容:
private void lvListaRadnika_MouseDown(object sender, MouseButtonEventArgs e)
{
DragDrop.DoDragDrop(lvListaRadnika, presenter.Selected, DragDropEffects.None);
}
private void ListView_Drop(object sender, DragEventArgs e)
{
DodavanjeRezervacije dr = new DodavanjeRezervacije(new DodavanjeRezervacijePresenter(null,true));
dr.Show();
}
Run Code Online (Sandbox Code Playgroud)
在这一点上,我需要发生一些事情,之后我会看到添加所有必要的检查,向对话提供数据以及添加一个装饰.
如果有人能够尽可能多地解释拖拽的方式我会非常感激,但在这一点上我真的需要这个来点火.
我目前正在开发一个应用程序,用户可以在画布上动态创建/移动TextBlocks.一旦他们将TextBlocks定位在他们想要的位置,他们就可以按下打印按钮,这将导致ZPL打印机打印当前显示在屏幕上的内容.
通过从每个TextBlock获取以下值来构建ZPL命令:
但是我找不到让打印输出类似于屏幕显示的方法.我想这是因为Canvas.Left和Canvas.Right的值与打印机DPI不匹配.
这是我目前正在使用的转换(因为我认为Canvas.Left = 1表示1/96英寸)(画布的左上角是0,0)
public double GetZplXPosition(UIElement uiElement)
{
int dpiOfPrinter = 300;
double zplXPosition = (Canvas.GetLeft(uiElement) / 96.0) * dpiOfPrinter;
return zplXPosition;
}
Run Code Online (Sandbox Code Playgroud)
我可以在"实际尺寸"中显示控件.使用的纸张将始终为A5(8.3英寸x 5.8英寸).
我想在Canvas周围使用一个视图框,其宽度和高度设置为830 x 580(A5的比例正确)但是这没有帮助.
有什么建议??
谢谢
我正在编写一个脚本来使用不同的输入文件和标志来批量执行快速排序,并以格式化的方式将它们输出到外部文件中。这是脚本的一部分,以便您可以理解上下文:
echo $file
echo "Naive Pivot"
count=1
while [ $count -lt 4 ]
do
echo "Run $count"
count=$(($count+1))
time ./quicksort -pn -so < $file
echo
done
Run Code Online (Sandbox Code Playgroud)
我尝试正常重定向它(从标准输出)
time ./quicksort -pn -so < $file > timing.txt
Run Code Online (Sandbox Code Playgroud)
并尝试从 stderr 重定向(尽管我可能做错了)。
time ./quicksort -pn -so < $file 2 >> timing.txt
Run Code Online (Sandbox Code Playgroud)
我也尝试过
/usr/bin/time -p -o timing.txt -a ./quicksort -pn -so < $file
Run Code Online (Sandbox Code Playgroud)
并使用标准 stderr 输出设置运行脚本,如下所示
./testData.sh > timing.txt 2 > timing.txt
Run Code Online (Sandbox Code Playgroud)
但是,它们都将所有计时数据附加在文件的末尾,而不是在我放在文件之前和之后的 echo 命令的输出之间。因此,虽然一切都在命令行中按顺序出现,但当我尝试运行将输出定向到文件的脚本时,所有的 echo.
我已经用尽了我的个人知识,需要帮助。如何让 time 命令(time 或 /usr/bin/time)正确输出到我的文件中与其执行相关的位置?提前致谢。
我试图在WPF中使用验证.我创建了一个NotNullOrEmptyValidationRule,如下所示:
public class NotNullOrEmptyValidationRule : ValidationRule
{
public override ValidationResult Validate(object value, CultureInfo cultureInfo)
{
if (String.IsNullOrEmpty(value as String))
return new ValidationResult(false, "Value cannot be null or empty");
return new ValidationResult(true, null);
}
}
Run Code Online (Sandbox Code Playgroud)
现在,我需要在我的应用程序中使用它.在我的App.xaml文件中,我为TextBox声明了Style.这是宣言.
<Style x:Key="textBoxStyle" TargetType="{x:Type TextBox}">
<Setter Property="Background" Value="Green"/>
<Style.Triggers>
<Trigger Property="Validation.HasError" Value="True">
<Setter Property="Background" Value="Red"/>
<Setter Property="ToolTip" Value="{Binding RelativeSource={RelativeSource Self},Path=(Validation.Errors)[0].ErrorContent}"/>
</Trigger>
</Style.Triggers>
</Style>
Run Code Online (Sandbox Code Playgroud)
现在,我想在我的TextBox上使用它,所以我使用以下代码:
<TextBox Style="{StaticResource textBoxStyle}">
<TextBox.Text>
<Binding>
<Binding.ValidationRules>
<NotNullOrEmptyValidationRule />
</Binding.ValidationRules>
</Binding>
</TextBox.Text>
</TextBox>
Run Code Online (Sandbox Code Playgroud)
Tag NotNullOrEmptyValidationRule上出现错误.XAML语法检查程序无法解析NotNullOrEmptyValidationRule.我甚至尝试过放置命名空间但它似乎不起作用.
是否有像System.Windows.Controls.GroupBox这样的控件可以隐藏其内容并只显示名称和扩展按钮?
我是WPF世界的新手.我有包含的treeView
树视图
任务 - >
Portfolio
---->portfolio1
Run Code Online (Sandbox Code Playgroud)
基准
Category
------>Name1 etc..
Run Code Online (Sandbox Code Playgroud)
我想知道如何在WPF中获取父节点值?例如,如果我选择portfolio1如何获取父 - 父值.在这种情况下Mandate.
简而言之,我想知道用户是否点击Name1 - >我应该获得基准测试,如果用户点击portfolio1,那么我应该获得投资组合.
非常感谢您的指导.
感谢和问候,
我有一个WPF窗口(window1),其所有者是window2.如果用户点击window2,桌面或其他任何东西使window1不在z顺序之上,我想将window1的可见性设置为隐藏.即,窗口要么位于顶部,要么隐藏.这可能吗?