草庐IT

uwp-xaml

全部标签

c# - 如何在 XAML 中围绕控件的中心进行旋转

我想将按钮旋转到90度,但它被截断了,因为它围绕(0,0)旋转。如果我不知道它的宽度(以像素为单位),如何让它围绕中心旋转(它是许多按钮的模板) 最佳答案 您必须将控件的RenderTransformOrigin设置为0.5、0.5。例如: 关于c#-如何在XAML中围绕控件的中心进行旋转,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questions/4132194/

c# - WPF MVVM 为什么使用 ContentControl + DataTemplate View 而不是直接的 XAML 窗口 View ?

为什么会这样?主窗口.xaml:将您的ExampleView.xaml设置为:然后像这样创建窗口:publicpartialclassApp:Application{protectedoverridevoidOnStartup(StartupEventArgse){base.OnStartup(e);MainWindowapp=newMainWindow();ExampleVMcontext=newExampleVM();app.DataContext=context;app.Show();}}什么时候可以这样?App.xaml:(设置启动窗口/View)ExampleView.xam

c# - WPF MVVM 为什么使用 ContentControl + DataTemplate View 而不是直接的 XAML 窗口 View ?

为什么会这样?主窗口.xaml:将您的ExampleView.xaml设置为:然后像这样创建窗口:publicpartialclassApp:Application{protectedoverridevoidOnStartup(StartupEventArgse){base.OnStartup(e);MainWindowapp=newMainWindow();ExampleVMcontext=newExampleVM();app.DataContext=context;app.Show();}}什么时候可以这样?App.xaml:(设置启动窗口/View)ExampleView.xam

c# - 如何在 XAML 中格式化 TimeSpan

我正在尝试格式化绑定(bind)到TimeSpan属性的文本block。如果属性是DateTime类型,它会工作,但如果它是TimeSpan,它会失败。我可以使用转换器完成它。但我正在尝试找出是否有其他选择。示例代码:publicTimeSpanMyTime{get;set;}publicWindow2(){InitializeComponent();MyTime=DateTime.Now.TimeOfDay;DataContext=this;}Xaml我希望文本block只显示小时数和分钟数。但它显示为:19:10:46.8048860 最佳答案

c# - 如何在 XAML 中格式化 TimeSpan

我正在尝试格式化绑定(bind)到TimeSpan属性的文本block。如果属性是DateTime类型,它会工作,但如果它是TimeSpan,它会失败。我可以使用转换器完成它。但我正在尝试找出是否有其他选择。示例代码:publicTimeSpanMyTime{get;set;}publicWindow2(){InitializeComponent();MyTime=DateTime.Now.TimeOfDay;DataContext=this;}Xaml我希望文本block只显示小时数和分钟数。但它显示为:19:10:46.8048860 最佳答案

c# - 如何使 WPF 组合框具有其在 XAML 中最宽元素的宽度?

我知道如何在代码中执行此操作,但这可以在XAML中完成吗?Window1.xaml:ComboBoxItem1ComboBoxItem2Window1.xaml.cs:usingSystem.Windows;usingSystem.Windows.Controls;namespaceWpfApplication1{publicpartialclassWindow1:Window{publicWindow1(){InitializeComponent();doublewidth=0;foreach(ComboBoxItemiteminComboBox1.Items){item.Measu

c# - 如何使 WPF 组合框具有其在 XAML 中最宽元素的宽度?

我知道如何在代码中执行此操作,但这可以在XAML中完成吗?Window1.xaml:ComboBoxItem1ComboBoxItem2Window1.xaml.cs:usingSystem.Windows;usingSystem.Windows.Controls;namespaceWpfApplication1{publicpartialclassWindow1:Window{publicWindow1(){InitializeComponent();doublewidth=0;foreach(ComboBoxItemiteminComboBox1.Items){item.Measu

c# - 使用 StringFormat 将字符串添加到 WPF XAML 绑定(bind)

我有一个WPF4应用程序,其中包含一个TextBlock,该TextBlock单向绑定(bind)到一个整数值(在本例中为摄氏温度)。XAML如下所示:这可以很好地显示实际温度值,但我想设置此值的格式,使其包含°C而不仅仅是数字(30°C而不仅仅是30)。我一直在阅读有关StringFormat的内容,并且看到了几个像这样的通用示例://formattheboundvalueasacurrency和//prefacetheboundvaluewithastringandformatitasacurrency不幸的是,我看到的所有示例都没有像我尝试做的那样将字符串附加到绑定(bind)值

c# - 使用 StringFormat 将字符串添加到 WPF XAML 绑定(bind)

我有一个WPF4应用程序,其中包含一个TextBlock,该TextBlock单向绑定(bind)到一个整数值(在本例中为摄氏温度)。XAML如下所示:这可以很好地显示实际温度值,但我想设置此值的格式,使其包含°C而不仅仅是数字(30°C而不仅仅是30)。我一直在阅读有关StringFormat的内容,并且看到了几个像这样的通用示例://formattheboundvalueasacurrency和//prefacetheboundvaluewithastringandformatitasacurrency不幸的是,我看到的所有示例都没有像我尝试做的那样将字符串附加到绑定(bind)值

Microsoft.Xaml.Behaviors.Wpf 的使用

System.Windows.Interactivity.WPF这个已经过时,可以使用 Microsoft.Xaml.Behaviors.Wpf,基本使用查不多,usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;usingSystem.Threading.Tasks;usingSystem.Windows;usingSystem.Windows.Controls;usingSystem.Windows.Data;usingSystem.Windows.Documents;usingSyst