Tag: wpf

date在WPF数据网格格式

我已经search了一个解决scheme的计算器,发现这个: 需要在dynamic构build的WPF DataGrid中格式化date 我的问题是,我从我的SQL服务器数据库加载一些数据,并希望在我的WPF应用程序在DataGrid中显示它们。 这工作得很好。 我唯一想改变的是date列的格式是“DD / MM / YYYY HH:MM:SS”,我想要“DD.MM.YYYY”。 好吧,然后我看了下面的链接,并在我的程序中尝试了这个: <Grid Width="648" Height="263"> <Grid.ColumnDefinitions> <ColumnDefinition Width="172*" /> <ColumnDefinition Width="90*" /> <ColumnDefinition Width="386*" /> </Grid.ColumnDefinitions> <DataGrid Name="dgBuchung" Height="213" HorizontalAlignment="Left" Margin="30,16,0,0" VerticalAlignment="Top" Width="595" AutoGenerateColumns="True" ItemsSource="{Binding}" Grid.ColumnSpan="3" Foreground="Black" BorderBrush="#FF688CAF" Opacity="1" Background="White" BorderThickness="1" > <!– <ab:DataGridTextColumn Header="Fecha Entrada" Width="110" Binding="{Binding date, StringFormat={}{0:dd/MM/yyyy}}" IsReadOnly="True" /> –> </DataGrid> </Grid> […]

DataGrid行内容垂直alignment

我有一个从WPF 4.0 RTM的常规DataGrid,我从数据库中放置数据。 为了使DataGrid的干净和清淡的风格我使用高/高的行,默认情况下,DataGrid排列行垂直位置的内容,但我想设置一个中心垂直alignment。 我已经尝试使用这个属性 VerticalAlignment="Center" 在DataGrid选项中,但它不能帮助我。 这里是一个XAML代码的例子,描述我的DataGrid没有中心垂直alignment: <DataGrid x:Name="ContentDataGrid" Style="{StaticResource ContentDataGrid}" ItemsSource="{Binding}" RowEditEnding="ContentDataGrid_RowEditEnding"> <DataGrid.Columns> <DataGridTextColumn Header="UserID" Width="100" IsReadOnly="True" Binding="{Binding Path=userID}" /> <DataGridTextColumn Header="UserName" Width="100" Binding="{Binding Path=userName}" /> <DataGridTextColumn Header="UserAccessLevel" Width="100" Binding="{Binding Path=userAccessLevel}" /> <DataGridTextColumn Header="UserPassword" Width="*" Binding="{Binding Path=userPassword}" /> </DataGrid.Columns> </DataGrid> 执行此代码的结果: 正如你所看到的,所有行的内容都有顶部垂直alignment。 为了获得每行内容的中心垂直alignment,我必须添加什么? 谢谢。

如何在代码中分配dynamic资源样式?

我想在代码中生成与XAML相同的代码: <TextBlock Text="Title:" Width="{Binding FormLabelColumnWidth}" Style="{DynamicResource FormLabelStyle}"/> 我可以做的文字和宽度,但我如何分配dynamic资源的风格: TextBlock tb = new TextBlock(); tb.Text = "Title:"; tb.Width = FormLabelColumnWidth; tb.Style = ???

“灰色”的WPFbutton图像?

我有一个简单的Button控件,它包含一个Image对象作为其内容。 我想这样设置的Image不透明度为0.5时, Button被禁用,以提供一个额外的视觉提示作为Button状态。 在XAML中完成这个结果最简单的方法是什么? 谢谢你的帮助。

如何在XAML中做一个简单的超链接?

我想要做的就是在XAML中做一个超级链接。 我已经尝试了一切。 我放弃。 这是什么语法? <StackPanel Width="70" HorizontalAlignment="Center"> <Hyperlink Click="buttonClose_Click" Cursor="Hand" Foreground="#555" Width="31" Margin="0 0 0 15" HorizontalAlignment="Right">Close</Hyperlink> <Button Width="60" Margin="0 0 0 3">Test 1</Button> <Button Width="60" Margin="0 0 0 3">Test 2</Button> <Button Width="60" Margin="0 0 0 3">Test 3</Button> <Button Width="60" Margin="0 0 0 3">Test 4</Button> </StackPanel> Visual Studio团队:在Visual Studio 2010中,我想让Clippypopup并说“看起来你正在尝试创build一个超链接”,并告诉我如何去做。 你不能用MEF做这个吗? 这将是复古的酷,而这些小小的“我怎么做我已经知道如何做的HTML”问题在XAML的学习过程中耗费了太多的时间。

任何方法来解决WPF的调用GC.Collect(2)除了reflection吗?

我最近不得不把这个怪物检入到生产代码中来操纵WPF类中的私有字段:(tl; dr我该如何避免这样做?) private static class MemoryPressurePatcher { private static Timer gcResetTimer; private static Stopwatch collectionTimer; private static Stopwatch allocationTimer; private static object lockObject; public static void Patch() { Type memoryPressureType = typeof(Duration).Assembly.GetType("MS.Internal.MemoryPressure"); if (memoryPressureType != null) { collectionTimer = memoryPressureType.GetField("_collectionTimer", BindingFlags.Static | BindingFlags.NonPublic)?.GetValue(null) as Stopwatch; allocationTimer = memoryPressureType.GetField("_allocationTimer", BindingFlags.Static | BindingFlags.NonPublic)?.GetValue(null) as Stopwatch; lockObject = […]

我在哪里可以find一些示例WPFanimation?

因为我是程序员,而不是艺术家或animation师,所以我没能在应用程序中展示WPF的最佳function。 虽然我有简单的buttonanimation像增长,或者有颜色淡入点击更明亮的东西,但我所寻找的是一些展示buttonanimation和一些展示面板更改animation展示WPF的最佳function。 通常我会去做更微妙的改变,但在一些情况下,我需要一些东西来展示使用WPF而不是WinForms技术的优点。 任何人都可以指向我的一些button样本和/或面板更改(从一个面板切换到下一个导航),真正显示的WPF,并有这个令人振奋的因素。 编辑 请不要指向http://codeproject.com或微软示例,因为我已经详细阅读了这些示例。 其实这里是我的rss阅读器的WPF网站列表(欢迎其他博客的build议): Lester的WPF博客 , Ask WPF , Expression Blend和Design , WPF Wonderland , nerdplusart , WPF的Karl , Windows Presentation Foundation SDK , WPF的Josh Smith , Rob Relyea – Xamlified , The Moth 。 我想要具体的例子,谢谢…

你需要在析构函数中移除一个事件处理程序吗?

我使用了一些UserControls ,它们在运行时在应用程序中创build和销毁(通过创build和closures内部具有这些控件的子窗口)。 这是一个WPF用户控件,并从System.Windows.Controls.UserControlinheritance。 没有可以覆盖的Dispose()方法。 PPMM是与我的应用程序相同的生命周期的Singleton 。 现在在我的(WPF) UserControl的构造函数中,我添加一个事件处理程序: public MyControl() { InitializeComponent(); // hook up to an event PPMM.FactorChanged += new ppmmEventHandler(PPMM_FactorChanged); } 我习惯于在析构函数中删除这样的事件处理程序: ~MyControl() { // hook off of the event PPMM.FactorChanged -= new ppmmEventHandler(PPMM_FactorChanged); } 今天我偶然发现,并想知道: 1)这是必要的吗? 还是GC照顾它? 2)这是否工作? 或者我将不得不存储新创build的ppmmEventHandler ? 我期待着你的回答。

x:Key和x:WPF中的名称有什么区别?

x:Key和x:Name WPF中的x:Name什么区别? 我不确定真正的区别是什么。

C#/ WPF:PropertyChanged在ViewModel中的所有属性?

我有一个这样的课: public class PersonViewModel : ViewModelBase //Here is the INotifyPropertyChanged Stuff { public PersonViewModel(Person person) { PersonEntity = person; } public Person PersonEntity { get { return PersonEntity.Name; } private set { PersonEntity.Name = value; RaisePropertyChanged("PersonEntity"); } public string Name { get { return PersonEntity.Name; } set { PersonEntity.Name = value; RaisePropertyChanged("Name"); } public int […]