Tag: wpf

WPF矩形 – 只是顶angular

我怎么才能有一个WPF rectange四舍五入的顶angular? 我创build了一个边框,并设置了CornerRadius属性,并在边框内添加了我的矩形,但不起作用,矩形未被四舍五入。 <Border BorderThickness="1" Grid.Row="0" Grid.ColumnSpan="2" CornerRadius="50,50,0,0" BorderBrush="Black"> <Rectangle Fill="#FF5A9AE0" Grid.Row="0" Grid.ColumnSpan="2" Stretch="UniformToFill" ClipToBounds="True"/> </Border>

如何将TabControl绑定到ViewModel的集合?

基本上我有我的MainViewModel.cs中: ObservableCollection<TabItem> MyTabs { get; private set; } 不过,我需要以某种方式不仅能够创build标签,而且还要在保持MVVM的同时将标签内容加载并链接到相应的视图模型。 基本上,我怎样才能得到一个用户控件作为tabitem的内容加载,并有该用户控件连线到适当的视图模型。 造成这个困难的部分是ViewModel不应该构造实际的视图项目,对吧? 或者可以吗? 基本上,这是MVVM是否合适: UserControl address = new AddressControl(); NotificationObject vm = new AddressViewModel(); address.DataContext = vm; MyTabs[0] = new TabItem() { Content = address; } 我只问,因为好,我构build一个ViewModel中的视图(地址控制),这对我来说听起来像一个MVVM no-no。

我怎样才能数据绑定到WPF / WP7中的列表框的string列表?

我正在尝试将一个string值列表绑定到一个列表框,以便它们的值逐行列出。 现在我用这个: <ListBox Margin="20" ItemsSource="{Binding Path=PersonNames}"> <ListBox.ItemTemplate> <DataTemplate> <StackPanel Orientation="Horizontal"> <TextBlock Text="{Binding Path=Id}"></TextBlock> </StackPanel> </DataTemplate> </ListBox.ItemTemplate> </ListBox> 但我不知道我应该把什么文本块,而不是Id ,因为它们都是string值,而不是自定义类。 另外它抱怨不必在MainPage中findPersonName,就像MainPage.PersonNames一样。 我将数据上下文设置为: DataContext="{Binding RelativeSource={RelativeSource Self}}" 我做错了吗?

在代码中设置WPF标签的样式属性?

在App.xaml中,我有以下代码: <Application.Resources> <Style x:Key="LabelTemplate" TargetType="{x:Type Label}"> <Setter Property="Height" Value="53" /> <Setter Property="Width" Value="130" /> <Setter Property="HorizontalAlignment" Value="Left" /> <Setter Property="Margin" Value="99,71,0,0" /> <Setter Property="VerticalAlignment" Value= "Top" /> <Setter Property="Foreground" Value="#FFE75959" /> <Setter Property="FontFamily" Value="Calibri" /> <Setter Property="FontSize" Value="40" /> </Style> </Application.Resources> 这是为了给我的标签提供一个通用的模板。 在主XAML代码中,我有以下代码行: <Label Content="Movies" Style="{StaticResource LabelTemplate}" Name="label1" /> 不过,我想通过代码初始化Style属性。 我努力了: label1.Style = new Style("{StaticResource […]

使WPF中的列表框项不可选

我有一个WPF的列表框,当他们select一个项目,它显示一个难看的颜色我可以使所有的项目不可选?

在TextBox中input执行viewmodels命令

当用户在TextBox中按下Enter键时,我想在viewmodel中执行一个命令。 绑定到button时,该命令起作用。 <Button Content="Add" Command="{Binding Path=AddCommand}" /> 但是我不能从TextBox中使用它。 我尝试了一个Inputbinding,但它没有工作。 <TextBox.InputBindings> <KeyBinding Command="{Binding Path=AddCommand}" Key="Enter"/> </TextBox.InputBindings> 我也尝试将工作button设置为默认值,但是在按下Enter键时不会执行。 谢谢你的帮助。

WPF附加属性数据绑定

我尝试使用绑定与附加的属性。 但不能得到它的工作。 public class Attached { public static DependencyProperty TestProperty = DependencyProperty.RegisterAttached("TestProperty", typeof(bool), typeof(Attached), new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault | FrameworkPropertyMetadataOptions.Inherits)); public static bool GetTest(DependencyObject obj) { return (bool)obj.GetValue(TestProperty); } public static void SetTest(DependencyObject obj, bool value) { obj.SetValue(TestProperty, value); } } XAML代码: <Window …> <StackPanel local:Attached.Test="true" x:Name="f"> <CheckBox local:Attached.Test="true" IsChecked="{Binding (local:Attached.Test), Mode=TwoWay, RelativeSource={RelativeSource Self}}" /> <CheckBox […]

WPFbutton中的多行文本

如何使用C#获取WPFbutton上的多行文本? 我已经看过在XAML中使用<LineBreak/>例子,但是我的button是用C#编程完全创build的。 button上的数字和标签对应于域模型中的值,所以我不认为我可以使用XAML来指定它。 我已经尝试了下面的天真的做法,但它不起作用。 Button b = new Button(); b.Content = "Two\nLines"; 要么 b.Content = "Two\r\nLines"; 无论哪种情况,我所看到的只是文本的第一行(“两”)。

签名时发生错误

我维护从另一个开发人员inheritance的大型WPF应用程序。 我使用ClickOnce发布它。 突然间,今天我得到了一个错误消息:错误2无法发布,因为项目build立失败。 1 1 错误3签署时发生错误:无法签署bin \ Debug \ app.publish \ setup.exe。 SignTool错误:未find符合所有给定条件的证书。 我有一个名为SomeName.snk的文件,在项目设置“签名”选项卡中引用。 我不知道今天发生了什么,导致了这个问题。 我使用VS 2012。

在WPF / C#中使用全局键盘钩子(WH_KEYBOARD_LL)

我从互联网上find的代码我自己缝合在一起WH_KEYBOARD_LL帮手类: 把下面的代码放到一些utils库中,让它成为YourUtils.cs : using System; using System.Diagnostics; using System.Runtime.InteropServices; using System.Runtime.CompilerServices; using System.Windows.Input; namespace MYCOMPANYHERE.WPF.KeyboardHelper { public class KeyboardListener : IDisposable { private static IntPtr hookId = IntPtr.Zero; [MethodImpl(MethodImplOptions.NoInlining)] private IntPtr HookCallback( int nCode, IntPtr wParam, IntPtr lParam) { try { return HookCallbackInner(nCode, wParam, lParam); } catch { Console.WriteLine("There was some error somewhere…"); } return […]