wpf-controls

Set Cursor Focus into Editable Combobox in WPF C#

一曲冷凌霜 提交于 2019-12-30 10:06:26
问题 I have editable combobox in WPF and I want to set focus from C#, I am using Combobox.Focus(), but it shows only selection but I want edit option where user can start entering. Update : Figured out FIX I ended up adding 'Loaded' Event to the Combobox and Wrote following Code to get focus in and it worked Fine private void LocationComboBox_Loaded(object sender, RoutedEventArgs e) { ComboBox cmBox = (System.Windows.Controls.ComboBox)sender; var textBox = (cmBox.Template.FindName("PART

Bindings on child dependency object of usercontrol not working

拈花ヽ惹草 提交于 2019-12-30 10:00:24
问题 I'm trying to get a binding to work on a child object of a user control. The Xaml looks like this: <MyGrid> <MyColumn ExtendedColumnData="{Binding ColumnToolTipDescriptions}"/> </MyGrid> Here is how the classes are defined: [ContentProperty("Columns")] public class MyGrid : UserControl { private MyColumnCollection _columns; [DesignerSerializationVisibility(DesignerSerializationVisibility.Content), Category("Data")] public MyColumnCollection Columns { get { if (_columns == null) _columns = new

Can I access ItemsHost of ItemsControl using reflection?

删除回忆录丶 提交于 2019-12-30 09:58:32
问题 I'm creating custom ItemsControl that is derived from DataGrid . I need to access ItemsHost that is the Panel that actually holds rows of DataGrid . I have seen som ugly tricks to do that but I consider them worse then using reflection. So can I access ItemsHost using reflection ? And how ? 回答1: Yes I can. It is simple - I've just created property in class inheriting from DataGrid : protected Panel ItemsHost { get { return (Panel) typeof (MultiSelector).InvokeMember("ItemsHost", BindingFlags

WPF Image, how to remove blur?

牧云@^-^@ 提交于 2019-12-30 08:03:56
问题 I have I need XAML: <Image Height="500" MouseLeftButtonDown="image_MouseLeftButtonDown" MouseRightButtonDown="image_MouseRightButtonDown" Name="image" Stretch="Fill" Width="500" />` C#: wbmap = new WriteableBitmap(50, 50, 500, 500, PixelFormats.Indexed8, palette); wbmap.WritePixels(new Int32Rect(0, 0, wbmap.PixelWidth, wbmap.PixelHeight), pixels, wbmap.PixelWidth * wbmap.Format.BitsPerPixel / 8, 0); image.Source = wbmap; 回答1: As tkerwin mentioned, change the BitmapScalingMode to

How to load a UserControl in WPF with reflection?

夙愿已清 提交于 2019-12-30 07:33:13
问题 private void Window_Loaded(object sender, RoutedEventArgs e) { var assm = Assembly.LoadFrom("wpflib.dll"); foreach (var t in assm.GetTypes()) { var i = t.GetInterface("test.ILib"); if (i != null) { var tmp = Activator.CreateInstance(typeof(UserControl)) as UserControl; this.stackPanel1.Children.Add(tmp); } } } tmp(UserControl1 in wpflib.dll) only contains a label and a textbox. Windows1 (test.exe) reference ILib.dll, and only contains a stackPanel1. But, why there is nothong in Windows1

Gray out the Desktop screen except a selected control in c#

南楼画角 提交于 2019-12-29 08:08:08
问题 I want to select a UI control to be clicked and gray out the rest of the desktop screen semi-transparently. I was thinking bitmap painting the whole screen but it is very slow process. I guess someone out there know in WPF how to do that. I don't have experiance in WPF. I wanted to do this on Windows 7. 回答1: Basically you want to show a top-level full screen transparent window which is not focusable and doesn't respond to input. You can then use this window to draw the overlay manually. I

Visible line count of a TextBlock

笑着哭i 提交于 2019-12-29 06:18:47
问题 If you set TextWrapping to "Wrap", a WPF TextBlock can have several lines of text. Is there a "clean" way to get the number of lines of text? I considered looking at the desired height and dividing it by an estimated height of each line. However, that seems quite dirty. Is there a better way? 回答1: One thing about WPF that's very nice is that all of the controls are very lookless. Because of this, we can make use of TextBox, which has a LineCount property (Why it's not a DependencyProperty or

How to set the DataSource of a DataGrid in WPF?

霸气de小男生 提交于 2019-12-29 06:13:48
问题 I need to set a table from a database to be the DataSource of a GridGrid in WPF. In Windows Forms the property is called DataSource but in WPF no such property exists, so how can i do it? 回答1: You can use the ItemsSource property : <ListView ItemsSource="{Binding YourData}"> <ListView.View> <GridView> <!-- The columns here --> </GridView> </ListView.View> </ListView> If you prefer to use code-behind rather than a binding, just give a name to the ListView and set the ItemsSource property in

Make my wpf application Full Screen (Cover taskbar and title bar of window)

坚强是说给别人听的谎言 提交于 2019-12-28 13:21:54
问题 I would like to make my application such that it can maximize to full screen means it hide the windows task bar and the title bar as well. And it should triggered by a button. I am trying to develop the my application window like this. Add my code snippet below <controls:MetroWindow x:Class="EDUI.MainWindow" xmlns:controls="clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:local="clr-namespace:EDiscoveryCore

Gmap.net Error in WPF

白昼怎懂夜的黑 提交于 2019-12-25 16:53:31
问题 After adding the reference component in the Toolbox, the following error occurs when trying to use the component: " A reference to "GMap.Net.WindowsPresentation,Version=1.6.0.0, Culture=neutral, PublicKeyToken=b8b9027b614afef" has been added to the project. In rder to use types from the new reference,press OK to restart the XAML designer. After the XAML Designer restarts, re-create the control on the artboard. " Already restarted Visual Studio, but not resolved. 回答1: This worked for me. Use