wpf-controls

Measure Control with double.PositiveInfinity WPF

耗尽温柔 提交于 2019-12-22 17:59:31
问题 I am working on a custom control that has a custom panel and inside the custom panel I have a small and simple MeasureOverride method that passes the size of double.PositiveInfinity to its children MeasureOverride method. The custom panel should take care of the layout and it should make children bigger or smaller depending on window size. If you have dealt with controls you should then know how wpf layout system works and that basically every child calls MeasureOverride which calls

How to compare the relative Z order of two WPF controls that are part of the same logical/visual tree?

被刻印的时光 ゝ 提交于 2019-12-22 17:50:20
问题 Is it possible to compare the relative Z order (which one will draw on top) of two WPF controls regardless of their relation in the logical/visual tree structure and what layout containers are used? I need this to be able to determine the visible regions of a control that might be overlapped by others. My plan is to start with the control geometry and intersect with the geometries of all the controls that will draw on top using CombinedGeometry having the GeometryCombineMode property set to

WPF Scale Transform and ScrollViewer - When Zoomed can't scroll beyond original size

核能气质少年 提交于 2019-12-22 16:58:07
问题 I have a StackPanel inside of a ScrollViewer. I have a slider that does a scale transform on the stackpanel to allow zoom-in and zoom-out functionality. The problem is that when I zoom in, the scrollviewer doesn't treat the content as being 'bigger'. So, if I scroll in a little and scroll as far right as I can go - it stops me before I get to the end of the content. If I zoom back out to the untransformed level, I see that it's stopping exactly at that point. If I zoom in a lot, I can only

TabControl.Items.Remove(TabItem) does not free memory used by TabItem

微笑、不失礼 提交于 2019-12-22 12:41:45
问题 I am having a WPF application where when I close a TabItem from TabControl using TabControl.Items.Remove(TabItem) does not free memory used by TabItem . It just makes TabItem invisible and TabItem object still remains in the memory. Is there any way to remove this TabItem object from memory ? Any help would be appreciated. 回答1: As far as I know all eventhandlers must be 'detached', also you should release all bindings on your tabItem. Also If I am not mistaken CommandBindings, KeyGestures can

How to call MahApps Metro Dialog box in Usercontrol in Wpf

╄→гoц情女王★ 提交于 2019-12-22 11:27:30
问题 When I tried to call MahApps Metro Dialog Boxes I am getting error while Passing Values while calling Dialog Control when Passing parameters I need to pass Metrowindow parameter But I need to call it in User control Below is the Method I will call when I need Dialog control public async void ShowMessageDialog(object sender, RoutedEventArgs e) { // This demo runs on .Net 4.0, but we're using the Microsoft.Bcl.Async package so we have async/await support // The package is only used by the demo

Adding context menu to leaf node in TreeView WPF

陌路散爱 提交于 2019-12-22 10:53:10
问题 In my WPF application, I want to add a context menu and its handler in ViewModel to the leaf nodes of my TreeView control. Here is how I have added the TreeView Control. <TreeView Name="treePads" ItemsSource="{Binding pads}" Width="190"> <TreeView.Resources> <HierarchicalDataTemplate DataType="{x:Type self:Pad}" ItemsSource="{Binding Members}"> <StackPanel Orientation="Horizontal"> <TextBlock Text="{Binding Name}" /> <TextBlock Text=" [" Foreground="Blue" /> <TextBlock Text="{Binding Members

WPF ListBox IndexFromPoint

梦想与她 提交于 2019-12-22 09:07:01
问题 I am performing a drag drop between WPF ListBoxes and I would like to be able to insert into the collection at the position it is dropped rather than the end of the list. Does anyone know of a solution that is similar to the WinForms ListBox IndexFromPoint function? 回答1: I ended up getting this work by using a combination of DragDropEvent.GetPosition, VisualTreeHelper.GetDescendantBounds and Rect.Contains. Here's what I came up with: int index = -1; for (int i = 0; i < collection.Count; i++)

How can I set the XAML for the first WPF RadioButton in a ListView control to be checked by default?

大憨熊 提交于 2019-12-22 05:58:25
问题 I have a WPF ListView control containing a number of RadioButton controls using data binding. I'd like the first RadioButton in the group to be checked by default, preferably set in the XAML rather than programmatically, but haven't managed to achieve this. My XAML for the control is: <ListView ItemsSource="{Binding OptionsSortedByKey}" > <ListView.ItemTemplate> <DataTemplate DataType="{x:Type Logging:FilterOptionsRadioListViewModel}"> <RadioButton Content="{Binding Value}" /> </DataTemplate>

Global static resources in a WPF class library?

空扰寡人 提交于 2019-12-22 05:39:10
问题 In a WPF application, you can put your global static resources in app.xaml .. like <Application.Resources> <!--Global View Model Locator--> <vm:ViewModelLocator x:Key="Locator" d:IsDataSource="True" /> </Application.Resources> That was from MVVM Light ;). Now, if your project is a wpf class library, what is a proper way to initialize such global static resources? 回答1: You can create a ResourceDictionary with your resources and merge the dictionaries using your code as below.

Draw a cross in WPF

心不动则不痛 提交于 2019-12-22 05:10:23
问题 I have a WPF Control. I need to have in background a cross, like this: After that, I'd be able to add other controls over my "crossed" background: How should I draw the cross, knowing that when I rezize the control, the cross should follow its size? 回答1: Quick and dirty way is to use lines and bind their coordinates to the width and height of some parent container. Something like this: <Grid Name="parent"> <Line X1="0" Y1="0" X2="{Binding ElementName='parent', Path='ActualWidth'}" Y2="