wpf-controls

How to get height and width of dynamically designed user control while added in wpf canvas control?

社会主义新天地 提交于 2019-12-10 14:22:25
问题 Hello I am developing one wpf application. I am adding object of myUserControl in canvas. i need height and with of added usercontrol. Now problem is that user control is design dynamically, i am creating grid and adding row and column according to configured by user, and i am giving auto in height and width. so i am not getting actual height and width of user control while adding it in canvas. 回答1: All UI elements derived from FrameworkElement have the ActualWidth and ActualHeight properties

How can I prevent the VS WPF designer putting margins on every object from the toolbox

送分小仙女□ 提交于 2019-12-10 14:21:13
问题 When I drag a control from the toolbox on to the Visual Studio 2008 WPF design surface, it sets a margin based on where I dropped it and a default size. Is there any way to prevent VS setting those? When I drop a control on a stackpanel I want it to flow in to the existing controls in the panel. Thanks! 回答1: I've never found a way to prevent this. I just type the XAML instead. EDIT : I wrote the above nearly three years ago. In the meantime, it would appear that the design-time experience has

How do create a DatePicker with only Sundays enabled?

青春壹個敷衍的年華 提交于 2019-12-10 13:45:44
问题 I need to allow user to select only the Sunday from my date picker so I need to disable other columns. But I couldn't find any solution for this. Currently I just check in the selection-changed event and clear the date if not valid. How do I disable the non-Sundays entirely? 回答1: The relevant section in @kalyan's suggested link regards blackout dates , and the DatePicker's BlackoutDates property, which lets you specify ranges of dates that users cannot select. That property is of type

Popup doesn't lose focus and close until I've clicked a control within it

回眸只為那壹抹淺笑 提交于 2019-12-10 13:38:15
问题 I'm trying to create a dropdown control consisting of a ToggleButton and a Popup control with a TabControl inside. My problem is, that the Popup doesn't close automatically unless I've clicked a certain control inside it. Consider the example below where the popup contains a TabControl which itself contains a Calendar control inside a TabItem. The expected behavior is that the Popup Closes whenever it loses focus (i.e. clicking the container window), but in order for the popup to fire a

Using events and Commands within ItemsControl in WPF

给你一囗甜甜゛ 提交于 2019-12-10 11:47:49
问题 Say I have a standard WPF ItemsControl bound to an ObservableCollection of "Dog" objects like so: <ItemsControl ItemsSource="{Binding Dogs}"> <ItemsControl.ItemTemplate> <DataTemplate> <StackPanel Orientation="Horizontal"> <TextBlock Text="{Binding Name}"/> <TextBlock Text="{Binding Breed}"/> <TextBlock Text="{Binding Weight}"/> </StackPanel> </DataTemplate> </ItemsControl.ItemTemplate> </ItemsControl> I want the user to be able delete any of the dogs in the collection. In the past I've been

Reference name space in another project in WPF xaml file

偶尔善良 提交于 2019-12-10 11:05:51
问题 I am referencing to a namespace of another project(class library, where all the models resides). as mentioned in the related questions, they have sloved the probem by adding the assembly as well to the .xaml file. But this did not work for me. That is why I am posting. I have 2 projects. WPF project itself. Class Library(this has all the viewmodels) WPF project has a reference to the Class Library.(Which should create a dll file of this Class Library in the bin of WPF project) I want to refer

WPF window invoked from Excel, Context menu shows and disappears immediately

情到浓时终转凉″ 提交于 2019-12-10 10:59:58
问题 I have a WPF window which has a ItemsControl which contains list of User controls. Each user control has a button and a list box. On the button i have a context menu which lists some option. When i ran the WPF window directly the context menu works perfectly. Now i have integrated the WPF form in a excel add in. on click of a button in addin the window show up. This works fine But when the window is called from addin and i right click the button to see the context menu options, it comes and

Conditional Formatting of WPF DataGrid Cell Depending on DataType

偶尔善良 提交于 2019-12-10 10:54:37
问题 I have a user control that inherits from the WPF DataGrid control and to which I pass different List of objects and, so, the columns of the grid depend (i.e. are automatically generated) on the class of object that I send through. <userc:cfDataGrid x:Name="grdResults" FontStyle="Normal" FontFamily="Microsoft Sans Serif" FontSize="14" RowHeight="30" AutoGenerateColumns="True" Margin="12" AlternatingRowBackground="Gainsboro" AlternationCount="2" ItemsSource="{Binding Results}" IsReadOnly="True"

How can I change the FontFamily in a WPF RichTextBox without modifying previous text

青春壹個敷衍的年華 提交于 2019-12-10 10:54:37
问题 When you use the FontFamily property of the RichTextBox it changes the FontFamily of the whole content inside the FlowDocument. The same way you can Execute a command like EditingCommands.ToggleBold, where it only changes the word under the caret or just the new text to be written, there should be a way to do the same thing with the FontsFamilies, and Color. 回答1: Maybe not the neatest solution but the you can inherit from the RichTextBox and add some behavior Declare your own Font Properties

How do mouse events work in WPF?

坚强是说给别人听的谎言 提交于 2019-12-10 10:44:56
问题 How do WPF controls know that Mouse Event Happend on it so that it can Raise its Mouse Event. For example How does a Button control know capture the MouseDown and MouseUp event and translate it into a click event. 回答1: Windows uses a Messaging model to notify GUI elements of what is happening. Windows puts these messages into a message queue, and each window is constantly checking this queue to see what messages are present. This is frequently called a message loop. The window is then