wpf-controls

How can I get SelectedItem and show Headers using ItemsControl?

跟風遠走 提交于 2020-01-03 01:42:33
问题 I am working on WPF Windows Application. I'm using ItemsControl to show collection list. Working on this I found there is no SelectedItem property in ItemsControl. Then how can I get the Selected Item from the ItemsControl. And also How can I display the Headers of ItemsControl. <ItemsControl ItemsSource="{Binding CustomSalesProducts, Mode=TwoWay}"> <ItemsControl.Template> <ControlTemplate TargetType="ItemsControl"> <Border> <ScrollViewer VerticalScrollBarVisibility="Auto"> <ItemsPresenter/>

WPF Click on control inside ListBoxItem does not select ListBoxItem

雨燕双飞 提交于 2020-01-02 09:12:13
问题 Hi I could not find any similar problem so I posted new question. In code below I create ListBox control with ListBoxItems that each contains radio button inside. When I click on the radio button it gets selects but parent ListBoxItem does not (ListBoxItem is not highlighted). How can I solve this issue? <ListBox Margin="0, 5, 0, 0" ItemsSource="{Binding mySource, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}" SelectionMode="Single"> <ListBox.ItemTemplate> <DataTemplate> <!-- Rabio

WPF control default size

試著忘記壹切 提交于 2020-01-02 07:20:13
问题 When defining custom resource themes for a wpf application, I can set width / height etc... How can I find the default value for these properties (i.e. the values used in the controls provided in the framework) ? 回答1: The default width and height for FrameworkElements is Double.NaN . If you don't specify a different size then WPF controls will automatically size themselves to try and fit their content, their containers or both. 回答2: WPF controls don't generally contain any kind of default

Synchronize Bindings of multiple Properties in a UserControl

故事扮演 提交于 2020-01-02 07:17:13
问题 I have an ugly race condition with a WPF usercontrol, which is some kind of extended ComboBox: The UserControl mainly defines two bindable DependencyProperties, one is the selected item, another one is a list, from which the selected item can be chosen. Both are bindable, so the control may be initialized with or without a selected item and both properties can be changed via binding (on DataContext change), further the selection may change due to user interaction. The UserControl contains a

Prevent ItemContainerStyle from overriding already set Style

谁说胖子不能爱 提交于 2020-01-02 07:00:13
问题 Is there a way of preventing a ItemContainerStyle from overriding an already set Style (via <Style TargetType="{x:Type MenuItem}"> ) for instance ? A style for a MenuItem is already defined within a ResourceDictionary XAML file, which is loaded on App startup : <ResourceDictionary> <Style TargetType="{x:Type MenuItem}"> <Setter Property="Foreground" Value="{DynamicResource TextForeground}"/> .. and so on </Style> </ResourceDictionary> I have the following MenuItem XAML definition. The

WPF Memory leak with derived TextBoxes

早过忘川 提交于 2020-01-02 05:32:11
问题 In one of the apps of mine I have a performance problem I can’t resolve: The app is built with input controls derived from the TextBox -class, having their own ControlTemplate in Themes\Generic.xaml . My problem is, that these controls will not be released after they are no more used. If I look at them with SciTech MemoryProfiler, I see that they are hold by an instance of System.Windows.Documents.TextEditor and the TextEditor -instance is hold through the finalizer queue. Memory profiler

WPF Cloned/Detached object edit problem - what is the standard?

痴心易碎 提交于 2020-01-01 19:47:07
问题 I am using an ObservableCollection to wrap some of my generated entity framework objects. When the user wants to edit some values , i am opening a popup windows that contains fields, and when the user changes and press save - the changes are saved to the database, and the binded controls are changes as it is an observablecollection. To prevent the user from working on the same binded object (it causes the visual change of every binded control on the same time) i want to use some functionality

WPF: Converting from UserControl to CustomControl

筅森魡賤 提交于 2020-01-01 19:15:41
问题 I have a WPF UserControl - SegmentConrol , that represents a line with some text and an array displaying the direction (>). As I have to customize this control styles, I decided to switch to a CustomControl, because I read this is better in a way... Now, I have some "troubles" to switch from UC to CC. Particularly, no idea where to put the <UserControl.Resources> part. If any of experts could advise me they are welcomed. Here is my UserControl: <UserControl x:Class="MyNamespace

In a combobox, how do I determine the highlighted item (not selected item)?

China☆狼群 提交于 2020-01-01 11:48:14
问题 First, fair warning: I am a complete newbie with C# and WPF. I have a combobox (editable, searchable) and I would like to be able to intercept the Delete key and remove the currently highlighted item from the list. The behavior I'm looking for is like that of MS Outlook when entering in email addresses. When you give a few characters, a dropdown list of potential matches is displayed. If you move to one of these (with the arrow keys) and hit Delete, that entry is permanently removed. I want

What is the difference between DataTemplate and DataContext in WPF?

强颜欢笑 提交于 2020-01-01 10:51:00
问题 I can set the relationship between View Model and view through following DataContext syntax: <UserControl.DataContext> <view_model:MainMenuModel /> </UserControl.DataContext> And I can also set the relationship between View Model and view through following DataTemplate syntax: <DataTemplate DataType="{x:Type viewModel:UserViewModel}"> <view:UserView /> </DataTemplate> What is the difference between the two? Is the second XAML not setting the data context of a view? 回答1: Your second XAML