Tag: xaml

WPF中的Application.DoEvents()在哪里?

我有下面的示例代码,每次按下一个button时缩放: XAML: <Window x:Class="WpfApplication12.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="MainWindow" Height="350" Width="525"> <Canvas x:Name="myCanvas"> <Canvas.LayoutTransform> <ScaleTransform x:Name="myScaleTransform" /> </Canvas.LayoutTransform> <Button Content="Button" Name="myButton" Canvas.Left="50" Canvas.Top="50" Click="myButton_Click" /> </Canvas> </Window> *的.cs public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); } private void myButton_Click(object sender, RoutedEventArgs e) { Console.WriteLine("scale {0}, location: {1}", myScaleTransform.ScaleX, myCanvas.PointToScreen(GetMyByttonLocation())); myScaleTransform.ScaleX = myScaleTransform.ScaleY = […]

OneWayToSource从XAML中的readonly属性绑定

我试图绑定到OneWayToSource作为模式的Readonly属性,但似乎这不能在XAML中完成: <controls:FlagThingy IsModified="{Binding FlagIsModified, ElementName=container, Mode=OneWayToSource}" /> 我得到: 无法设置属性“FlagThingy.IsModified”,因为它没有可访问的set访问器。 IsModified是FlagThingy上的只读DependencyProperty 。 我想将该值绑定到容器上的FlagIsModified属性。 要清楚: FlagThingy.IsModified –> container.FlagIsModified —— READONLY —– —– READWRITE ——– 这可能只使用XAML? 更新:好吧,我通过在容器上设置绑定来解决这个问题,而不是在FlagThingy 。 但我仍然想知道这是否可能。

在WPF中的XAML中设置DataContext

我有以下代码: MainWindow.xaml <Window x:Class="SampleApplication.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="MainWindow" Height="350" Width="525" DataContext="{Binding Employee}"> <Grid> <Grid.RowDefinitions> <RowDefinition Height="Auto" /> <RowDefinition Height="Auto" /> </Grid.RowDefinitions> <Grid.ColumnDefinitions> <ColumnDefinition Width="Auto" /> <ColumnDefinition Width="200" /> </Grid.ColumnDefinitions> <Label Grid.Row="0" Grid.Column="0" Content="ID:"/> <Label Grid.Row="1" Grid.Column="0" Content="Name:"/> <TextBox Grid.Column="1" Grid.Row="0" Margin="3" Text="{Binding EmpID}" /> <TextBox Grid.Column="1" Grid.Row="1" Margin="3" Text="{Binding EmpName}" /> </Grid> </Window> Employee.cs namespace SampleApplication […]

如何在wpf中创build自定义的窗口镶边?

我怎样才能创build一个基本的自定义窗口铬为WPF窗口,不包括closuresbutton,仍然是一个可移动和可resize的窗口?

从XAML调用参数化的构造函数

在使用WPF时,我注意到当我将一个控件添加到一个XAML文件时,默认的构造函数被调用。 有没有办法调用一个参数化的构造函数?

在WPF中绑定WebBrowser的Source属性

有谁知道如何绑定WPF(3.5SP1)WebBrowser的.Source属性? 我有一个列表视图,我想在左边有一个小的WebBrowser,内容在右边,并绑定每个绑定到列表项的对象的URI的每个WebBrowser的源数据绑定。 这是我迄今为止的概念certificate,但是“ <WebBrowser Source="{Binding Path=WebAddress}" ”不能编译。 <DataTemplate x:Key="dealerLocatorLayout" DataType="DealerLocatorAddress"> <StackPanel Orientation="Horizontal"> <!–Web Control Here–> <WebBrowser Source="{Binding Path=WebAddress}" ScrollViewer.HorizontalScrollBarVisibility="Disabled" ScrollViewer.VerticalScrollBarVisibility="Disabled" Width="300" Height="200" /> <StackPanel Orientation="Vertical"> <StackPanel Orientation="Horizontal"> <Label Content="{Binding Path=CompanyName}" FontWeight="Bold" Foreground="Blue" /> <TextBox Text="{Binding Path=DisplayName}" FontWeight="Bold" /> </StackPanel> <TextBox Text="{Binding Path=Street[0]}" /> <TextBox Text="{Binding Path=Street[1]}" /> <TextBox Text="{Binding Path=PhoneNumber}"/> <TextBox Text="{Binding Path=FaxNumber}"/> <TextBox Text="{Binding […]

绑定input键上的文本框

TextBox上的默认数据绑定是TwoWay ,只有当TextBox失去焦点时,它才会将文本提交给属性。 当我按下TextBox上的Enter键时,是否有任何简单的XAML方法可以使数据绑定发生? 我知道在后面的代码中执行起来很容易,但想象一下,如果这个TextBox是在一些复杂的DataTemplate里面的话。

Generic.xaml有什么特别之处?

我一直在试图找出如何组织我的ResourceDictionary文件重用和与我的团队的其他成员共享。 我一直在遇到“Generic.xaml”,但是如果我在Generic.xaml的MSDN上看,或者只是做一个谷歌search,我似乎只是得到博客文章和论坛问题碰巧提到它 – 我似乎无法打击任何真正的权威和明确。 Generic.xaml和MyRandomlyNamedResourceDictionary.xaml有什么区别? 看起来像这样,我必须引用Source属性中存储在库中的ResourceDictionaries。 例如,: <Application.Resources> <ResourceDictionary Source="/CommonLibraryWpfThemes;component/Themes/Generic.xaml" </Application.Resources> 那么Generic.xaml究竟提供了什么好处呢? 如果我不试图给我的应用程序多个“外观”(即,如果我只有一个主题),它有什么目的吗?

从ToolTip或ContextMenu的RelativeSource绑定

我在这里做错了什么? <GridViewColumn> <GridViewColumn.CellTemplate> <DataTemplate> <Button> <Button.ToolTip> <TextBlock Text="{Binding Path=Title, RelativeSource={RelativeSource AncestorType=Window}}" /> 这只是一个简单的例子,它不起作用:)实际上,我需要从窗口的DataContext范围内的另一个属性获取值。 帮帮我

任何方式来使WPF文本块可选?

我想让Witty (一个开源的Twitter客户端)中显示的文本可选。 它当前使用自定义文本块显示。 我需要使用TextBlock,因为我正在使用文本块的内联来显示和格式化@username和链接作为超链接。 频繁的请求是能够复制粘贴文本。 为了做到这一点,我需要使TextBlock可选。 我试图通过显示文本使用只读文本框样式来看起来像一个文本块,但这不会工作在我的情况,因为一个文本框没有内联。 换句话说,我无法在TextBox中单独设置样式或格式,就像我可以使用TextBlock一样。 有任何想法吗?