Tag: xaml

WPF UserControl如何inheritanceWPF UserControl?

下面的WPF UserControl称为DataTypeWholeNumber它的作品。 现在我想创build一个名为DataTypeDateTime和DataTypeEmail等的UserControl 许多依赖属性将被所有这些控件共享,因此我想将它们的通用方法放到一个BaseDataType中,并让这些UserControl中的每一个都inheritance这个基types。 但是,当我这样做时,我得到的错误:部分声明可能没有不同的基类 。 那么我怎样才能实现与UserControl的inheritance,所以共享的function都在基类? using System.Windows; using System.Windows.Controls; namespace TestDependencyProperty827.DataTypes { public partial class DataTypeWholeNumber : BaseDataType { public DataTypeWholeNumber() { InitializeComponent(); DataContext = this; //defaults TheWidth = 200; } public string TheLabel { get { return (string)GetValue(TheLabelProperty); } set { SetValue(TheLabelProperty, value); } } public static readonly DependencyProperty TheLabelProperty = DependencyProperty.Register("TheLabel", […]

如何使覆盖控制高于所有其他控件?

我需要使控件出现在所有其他控件之上,所以它会部分覆盖它们。

当TextBox具有焦点时,UserControl中的KeyBinding不起作用

以下情况。 我有一个用五个键绑定的用户控件。 当TextBox具有焦点时,UserControl的键绑定停止点燃。 有没有办法解决这个“问题”? <UserControl.InputBindings> <KeyBinding Key="PageDown" Modifiers="Control" Command="{Binding NextCommand}"></KeyBinding> <KeyBinding Key="PageUp" Modifiers="Control" Command="{Binding PreviousCommand}"></KeyBinding> <KeyBinding Key="End" Modifiers="Control" Command="{Binding LastCommand}"></KeyBinding> <KeyBinding Key="Home" Modifiers="Control" Command="{Binding FirstCommand}"></KeyBinding> <KeyBinding Key="F" Modifiers="Control" Command="{Binding SetFocusCommand}"></KeyBinding> </UserControl.InputBindings> <TextBox Text="{Binding FilterText, UpdateSourceTrigger=PropertyChanged}"> <TextBox.InputBindings> <KeyBinding Gesture="Enter" Command="{Binding RelativeSource={RelativeSource AncestorType={x:Type UserControl }}, Path=DataContext.FilterCommand}"></KeyBinding> </TextBox.InputBindings> </TextBox> 看来function键( F1等)和ALT + [键]工作。 我认为CTRL和SHIFT修饰符以某种方式阻止事件冒泡到UserControl。

名称“XYZ”不存在于名称空间“clr-namespace:ABC”

我正在创build一些标记扩展,并开始得到很奇怪的VS行为。 我已经提出并在单独的解决scheme中指出了这个问题。 问题是VS不能在XAML中创build一个CLR对象。 这里是: 视图: <Window x:Class="WpfApplication4.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:wpfApplication4="clr-namespace:WpfApplication4"> <Window.Resources> <wpfApplication4:Dog x:Key="doggy" /> </Window.Resources> <Grid /> </Window> 代码后面: using System.Windows; namespace WpfApplication4 { public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); } } } 狗类: namespace WpfApplication4 { public class Dog { } } App.Xaml(App.Xaml.cs中没有代码): <Application x:Class="WpfApplication4.App" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" StartupUri="MainWindow.xaml"> <Application.Resources> […]

WPF TreeView HierarchicalDataTemplate – 绑定到具有多个子集合的对象

我试图让TreeView绑定我的集合,以便所有组显示嵌套组,每个组将显示条目。 我如何使用HierarchicalDataTemplate以便TreeView将处理SubGroups和Entries集合? 组显示子组和条目: Example: Group1 –Entry –Entry Group2 –Group4 —-Group1 ——Entry ——Entry —-Entry —-Entry –Entry –Entry Group3 –Entry –Entry 对象: namespace TaskManager.Domain { public class Entry { public int Key { get; set; } public string Name { get; set; } } } namespace TaskManager.Domain { public class Group { public int Key { get; […]

如何获取WPF中当前屏幕的大小?

我知道我可以通过使用获取主屏幕的大小 System.Windows.SystemParameters.PrimaryScreenWidth; System.Windows.SystemParameters.PrimaryScreenHeight; 但是,我如何获得当前屏幕的大小? (多屏用户不总是使用主屏幕,并不是所有的屏幕都使用相同的分辨率,对吧?) 能够从XAML访问大小将是很好的,但是从代码(C#)来完成就足够了。

OneWayToSource绑定似乎在.NET 4.0中被破坏

OneWayToSource绑定似乎在.NET 4.0中被破坏 我有这个简单的Xaml <StackPanel> <TextBox Text="{Binding TextProperty, Mode=OneWayToSource}"/> <Button/> </StackPanel> 我的代码看起来像这样 public MainWindow() { InitializeComponent(); this.DataContext = this; } private string m_textProperty; public string TextProperty { get { return "Should not be used in OneWayToSource Binding"; } set { m_textProperty = value; } } 在.NET 3.5中,这个工作正如你可能除外。 在TextBox放置一些文本,按下Tab键使其失去焦点, TextProperty更新文本TextBoxinput的任何文本 在.NET 4.0中 ,如果我在TextBox键入一些文本,然后按下Tab使其失去焦点,则TextBox将恢复为TextProperty的值(意思是“不应在OneWayToSource绑定中使用” )。 这是重新阅读旨在.NET 4.0中的OneWayToSource绑定? 我只是希望TextBox将其值推入TextProperty而不是其他方式。 […]

我怎样才能让ScrollViewer在StackPanel中工作?

在下面的WPF XAML ScrollViewer不起作用(它显示一个滚动条,但你不能滚动和内容离开窗口底部)。 我可以改变外面的StackPanel到一个网格,它会工作。 但是,在我的应用程序中,我重现了以下代码,我需要一个外部的StackPanel。 我该怎么做的StackPanel使ScrollViewer显示一个可用的滚动条? 例如VerticalAlignment =“Stretch”Height =“Auto”不起作用。 <StackPanel> <ScrollViewer> <StackPanel> <TextBlock Text="This is a test"/> <TextBlock Text="This is a test"/> <TextBlock Text="This is a test"/> <TextBlock Text="This is a test"/> <TextBlock Text="This is a test"/> <TextBlock Text="This is a test"/> <TextBlock Text="This is a test"/> <TextBlock Text="This is a test"/> <TextBlock Text="This is […]

该名称不存在于XAML中的命名空间错误中

使用VS2012在VB.NET WPF应用程序上工作。 我有一个简单的MusicPlayer教程应用程序,我正在使用学习WPF。 我将本教程的C#版本逐步转换为VB.NET。 它在应用程序中有两个类都在同一个命名空间下。 我能够引用XAML中的命名空间,但是当我尝试引用XAML中的类对象时,出现错误,我无法编译。 奇怪的是,智能感知既可以通过xmlns:c =标签来引用命名空间,也可以在使用<c:来键入类对象时正常工作<c:但是,该对象带有下划线,并且会生成错误,试图在devise器中生成或工作。 .vb类文件位于名为\ Controls的文件夹中。 主项目根目录空间有意留空。 这个类是这样编码的… Namespace MusicPlayer.Controls Public Class UpdatingMediaElement …. code here End Public End Namespace xaml看起来像这样 (在<Window >标签中定义的名称空间 xmlns:c="clr-namespace:MusicPlayer.Controls" (在<Grid>定义的对象) <c:UpdatingMediaElement Name="MyMediaElement" /> (显示错误)命名空间“clr-namespace:MusicPlayer.Controls”中不存在名称“UpdatingMediaElement”。 不知道什么是错的或如何解决它?

在WPF中使用超链接的示例

我见过几个build议,你可以通过Hyperlink控制添加到WPF应用程序的Hyperlink 。 以下是我想要在代码中使用它的方法: <Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" x:Class="BookmarkWizV2.InfoPanels.Windows.UrlProperties" Title="UrlProperties" Height="754" Width="576"> <Grid> <Grid.RowDefinitions> <RowDefinition></RowDefinition> <RowDefinition Height="40"/> </Grid.RowDefinitions> <Grid> <ScrollViewer ScrollViewer.VerticalScrollBarVisibility="Auto" Grid.RowSpan="2"> <StackPanel > <DockPanel LastChildFill="True" Margin="0,5"> <TextBlock Text="Url:" Margin="5" DockPanel.Dock="Left" VerticalAlignment="Center"/> <TextBox Width="Auto"> <Hyperlink NavigateUri="http://www.google.co.in"> Click here </Hyperlink> </TextBox> </DockPanel > </StackPanel> </ScrollViewer> </Grid> <StackPanel HorizontalAlignment="Right" Orientation="Horizontal" Margin="0,7,2,7" Grid.Row="1" > <Button Margin="0,0,10,0"> <TextBlock […]