wpf-controls

Getting current size of WPF controls

左心房为你撑大大i 提交于 2019-12-08 15:53:52
问题 I have Image control in my Window. The size of this Image control is set to "Auto". <Image x:Name="videoImg" Stretch="Fill" Height="Auto" Width="Auto" /> When i try to get access, it returns 0. How to see real size of this control? It resizes with window. 回答1: You can use .ActualHeight and .ActualWidth to get the rendered Height / Width of a control 回答2: The thing is, the Width and Height properties let you express the desired size , whereas what you want is the rendered size - which can be

WPF disable main window while second window is open until it closed

走远了吗. 提交于 2019-12-08 15:04:58
问题 I have a WPF application with a main window and a second window that can be opened from a button in the main window. I want the main window to be disabled while the second window is open as an "About" window in Visual Studio. 回答1: Try this ShowDialog method instead of Show to open the second window as a dialog. You have a WPF project already with a window. This app should work. Right click on project and Add new Window. You name it Window1.xaml You would now notice Window1.xaml and Window1

WPF Prism Region inside a tab control isn't in the Region List

跟風遠走 提交于 2019-12-08 12:32:58
问题 I've got a tab control with a region attached to it and I've also got a content control inside my tab controls content with another region. The problem I'm having is - if I call RegisterViewWithRegion it adds the view to the region no problem (first time that is, get issues if you swap tabs). But this isn't very flexible and I'm looking for a better way to do that. When I look inside IRegionManager.Regions as well - I can only see the two top level regions. I cant see my sub region

Filtering Datagrid Binded to DataTable WPF

三世轮回 提交于 2019-12-08 12:10:59
问题 I am trying to create a filtering system for a DataGrid in WPF just as in the link - http://www.codeproject.com/Articles/42227/Automatic-WPF-Toolkit-DataGrid-Filtering I am using the same library that they are using but the thing is I need to bind my DataGrid to a datatable... And there is where the error is.. the filter library works perfectly as long as the ItemSource is a LIST but stops to work when the ItemSource is a DataTable... Any Alternatives or Suggestions??? Working Examples

WPF Canvas-based ItemsControl with minimum recycled items?

自作多情 提交于 2019-12-08 11:35:32
问题 I'm using an ItemsControl with a Canvas as its backing Panel . I often need to .Clear() the ObservableCollection is the ItemsControl's ItemSource , and then add new information to it, which causes all the controls to be destroyed and new UserControl s to be created, which is very sluggish. How can I force the ItemsControl to retain a certain amount of containers even after I call .Clear(), and then reuse them when new items are added to the ItemSource? 回答1: I am not sure how efficient this

Setting focus to UI control in WPF MVVM Way on Validation.HasError

夙愿已清 提交于 2019-12-08 11:17:00
问题 Problem: Validation.HasError automatically highlights the control that has Error via INotifyDataErrorInfo implementation. My problem is i need to set focus on that specific control when it has ERror. How do I do That? 回答1: I have gone through several articles in Stackoverflow and other sites and i finally wish to address this problem. <Style TargetType="TextBox" > <Setter Property="OverridesDefaultStyle" Value="false"/> <Setter Property="VerticalAlignment" Value="Center"/> <Setter Property=

Conditional DataTemplates when binding to a collection

那年仲夏 提交于 2019-12-08 07:51:12
问题 Sample Application: The sample application that the supplied code belongs to displays a list of Vehicle objects via Binding. The Vehicle class is a top level class that subclasses can derive from e.g. Car and Bike . The sample application at the moment displays the owner's name of the Vehicle . Sample Model code: public class Vehicle { private string _ownerName; public string ownerName { get { return _ownerName; } set { _ownerName = value; } } } public class Car : Vehicle { public int doors;

How can I move the caretposition programatically in a RichTextBox?

ε祈祈猫儿з 提交于 2019-12-08 07:00:27
问题 I have a RichTextBox with custom formatting on special bits of text in it. However there is a bug where after a character is inserted, the caret is placed before the newly inserted character instead of after. This is because for every edit, the code recalculates the content to apply the custom formatting and then sets the CaretPosition like so... protected override void OnTextChanged(TextChangedEventArgs e) { base.OnTextChanged(e); currentPos = CaretPosition.GetNextInsertionPosition

Creating a Window.Title Attached Property

妖精的绣舞 提交于 2019-12-08 06:29:46
问题 I have a Window shell that is basically: <Window> <ContentPresenter Content="{Binding}" /> </Window> Injected into the ContentPresenter at run-time are UserControls. What I want to be able to do is write: <UserControl Window.Title="The title for my window"> [...] </UserControl> So that the Window title is updated using the UserControl Window.Title property. I have a feeling this can be achieved using attached properties. Can anyone start me off in the right direction? Daniel 回答1: C#: public

HeaderTemplate in DataGrid WPF

孤者浪人 提交于 2019-12-08 05:24:43
问题 I need to have a kind of a datepicker in my datagrid header for one of the columns. When the user selects the date from this header datepicker, the system should bind this date to all the column cells with the date. Is there a way to do it? 回答1: the best way is to set the header's dataTemplate to a custom template containing a DatePicker whose Date is bound to one of the DataGrid's DataContext's properties, then bind the cells in this specific column to the same property. something like this: