DateTimePicker Missing Dropdown Button - wpf

I have two xctk:DateTimePickers on a user control. I don't think that is the issue, but their IsEnabled property is bound to a radio button IsChecked property on the same user control.
The issue is that the only one of them can have the drop-down button that reveals the calendar at a time. When it is loaded, only the last one to load has one, but when they are being enabled, only the other has it.
There is a similar issue with the TimePicker on their calendar display.
The issue persists even without the resources so there is probably nothing relevant there.
Might also be important to note that the button is actually there, it appears that the arrow is what's missing.
Here is the xaml for this particular part:
<StackPanel HorizontalAlignment="Stretch" Margin="10">
<RadioButton GroupName="dateOptions" IsChecked="True" ToolTip="Show the most recent date at 1Hz refresh rate." Margin="{StaticResource DefaultMargin }">Scope Mode</RadioButton>
<RadioButton x:Name="RadioButtonLogBrowser" IsChecked="{Binding IsDateRange, Mode=OneWayToSource, UpdateSourceTrigger=PropertyChanged}" GroupName="dateOptions" ToolTip="Browse History by date range" Margin="{StaticResource DefaultMargin }">Log Browser Mode</RadioButton>
<Grid Margin="20,0,0,0" IsEnabled="{Binding IsChecked, ElementName=RadioButtonLogBrowser,Mode=OneWay, UpdateSourceTrigger=PropertyChanged}">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Label Margin="{StaticResource DefaultMargin }">Start Date:</Label>
<xctk:DateTimePicker HorizontalAlignment="Stretch" x:Name="StartDate" Grid.Row="1" Margin="{StaticResource DefaultMargin }" >
<xctk:DateTimePicker.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="..\..\GeneralResources.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</xctk:DateTimePicker.Resources>
</xctk:DateTimePicker>
<Label Grid.Row="2" Margin="{StaticResource DefaultMargin }">Start Date:</Label>
<xctk:DateTimePicker HorizontalAlignment="Stretch" x:Name="EndDate" Grid.Row="3" Margin="{StaticResource DefaultMargin }">
<xctk:DateTimePicker.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="..\..\GeneralResources.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</xctk:DateTimePicker.Resources>
</xctk:DateTimePicker>
</Grid>```

To whoever have this problem in the future:
That was a known component issue and it was solved in the last release version 4.3.0.
In DateTimePicker, using more than one custom DateTimePicker now displays the dropDown button on each of the DateTimePicker.
ref: https://github.com/xceedsoftware/wpftoolkit/wiki/Improvements-in-v4.3.0

Related

Why is my WPF ContextMenu Item disabled?

I have a small but annoying problem with my ContextMenu in a WPF application.
I use a DataTemplate for my List of ViewModel-objects to create the visual elements. In the DataTemplate I simply set my UserControl like this:
<!-- Define a data-template for the 'RoomViewModel' class. This generates the UI for each node. -->
<DataTemplate DataType="{x:Type model:RoomViewModel}">
<network:RoomView network:ConstraintView.ArgumentChanged="ConstraintView_ArgumentChanged"></network:RoomView>
</DataTemplate>
I want the RoomView to have a ContextMenu where a RelayCommand should be executed if the user clicks on the MenuItem. My UserControl for the RoomView looks like this at the moment:
<UserControl x:Name="userControl" x:Class="NetworkUI.RoomView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:network="clr-namespace:NetworkUI"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300" DataContextChanged="userControl_DataContextChanged">
<UserControl.Resources>
<!-- UI commands -->
<RoutedCommand x:Key="Commands.NewConstraintCmd"></RoutedCommand>
</UserControl.Resources>
<UserControl.CommandBindings>
<CommandBinding x:Name="newConst" Command="{StaticResource Commands.NewConstraintCmd}" Executed="NewConstraint_Executed"></CommandBinding>
</UserControl.CommandBindings>
<Grid Width="Auto" Height="Auto" MinWidth="50" >
<Grid.RowDefinitions>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
</Grid.RowDefinitions>
<Grid Grid.Row="0" Width="Auto" Height="20" MinWidth="50" >
<Rectangle Stroke="Black" Fill="White" RadiusX="4" RadiusY="4" SnapsToDevicePixels="True" ></Rectangle>
<Grid Margin="-4" >
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" MinWidth="10" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<network:EditableTextBlock Grid.Column="1" Grid.Row="1" x:Name="nameTextBox" Text="{Binding Name, Mode=TwoWay}" HorizontalAlignment="Center" VerticalAlignment="Center" BorderBrush="{x:Null}" />
<network:ConnectorItem Grid.Row="1" Grid.Column="0" DataContext="{Binding Connectors[0]}" />
<network:ConnectorItem Grid.Row="1" Grid.Column="2" DataContext="{Binding Connectors[1]}" />
</Grid>
</Grid>
<StackPanel Grid.Row="1" x:Name="roomProperties" Width="Auto" HorizontalAlignment="Stretch" >
<ItemsControl ItemsSource="{Binding PropertyGroups}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<network:ConstraintCollectionView></network:ConstraintCollectionView>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</StackPanel>
</Grid>
<UserControl.ContextMenu>
<ContextMenu x:Name="contextMenu">
<MenuItem Header="new Constraint" Command="{StaticResource Commands.NewConstraintCmd}"></MenuItem>
</ContextMenu>
</UserControl.ContextMenu>
</UserControl>
I am not really sure if my UserControl code is ok. In my CodeBehind file I define a
public ICommand NewConstraintCmd;
-Command that should be executed when the user clicks the Item. My Executed handler is simple and looks like this:
private void NewConstraint_Executed(object sender, ExecutedRoutedEventArgs e) {
ViewModel.AddConstraint();
}
The ViewModel is indeed a RoomViewModel and the NewConstraintCmd is set in the DataContextChanged - event (not displayed here).
My simple question is, why is my ContextMenu-Item always disabled? I mean the RelayCommand.CanExecute is never checked, is this the problem maybe?
I didn't find any solution for my problem yet.
Thank you for any help!
Thank you Rohit Vats! I changed my ICommand definition to this:
public static readonly ICommand NewConstraint = new RelayCommand((rvm) => AddConstraint(rvm));
Since this is a static method I needed the parameter (the DataContext of my RoomView).
My Method is defined like this now:
private static void AddConstraint(object rvm) {
if (rvm is RoomViewModel)
(rvm as RoomViewModel).AddConstraint();
}
So first the parameter is checked and if it is ok (a RoomViewModel object) I call the actual function on the object.
I have no idea why it works now, really :/.
My XAML code for the MenuItem now looks like this:
<MenuItem Header="new Constraint" Command="network:RoomView.NewConstraint" CommandParameter="{Binding}"></MenuItem>
As mentioned before I need the CommandParameter to call a function on it. Since the needed Object is my DataContext I just use the {Binding} to pass the object.
This really works fine now, I hope it will work with InputBindings as well in the future :)!
Thank you again for the help!

Grief with WPF UserControl with ListBox and TextBox Can't get textwrapping to work

I am trying to produce a simple User Control that allows a user to enter notes and review the notes he or she has taken. For now, I have a ListBox to show previous notes and a TextBox to enter a new note. The ListBox also uses TextBoxs to show the individual notes. The logic is all working. Now I'd just like the control to look a little nicer. I am not seeing text wrapping when one of the notes is long. Nor am I seeing text wrapping on the TextBox where I enter a new note. I have tried to research this and have found the warnings about using StackPanels. Hence no stack panels here! Here is my XAML
<UserControl.Resources>
<DataTemplate x:Key="DefaultTemplate">
<Grid x:Name="GridItem" >
<Grid.ColumnDefinitions>
<ColumnDefinition />
</Grid.ColumnDefinitions>
<TextBox x:Name="NoteText" Grid.Column="0" Margin="0,5,5,0" Text="{Binding Path=NoteText}" TextWrapping="Wrap" />
</Grid>
</DataTemplate>
</UserControl.Resources>
<Grid Name="LayoutRoot">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<TextBox Grid.Row="0" Text="{Binding Path=NewNoteText, UpdateSourceTrigger=PropertyChanged}" LostFocus="TextBox_LostFocus">
<TextBox.InputBindings>
<KeyBinding Command="{Binding Path=AddNote}" Key="Enter"/>
</TextBox.InputBindings>
</TextBox>
<ListBox Grid.Row="1" ItemsSource="{Binding Path=Notes}" Margin="5" ItemTemplate="{DynamicResource DefaultTemplate}" SelectionChanged="NotesControl_SelectionChanged">
</ListBox>
</Grid>
I have tried specifying Width="*" in the UserResources. That made no difference. I don't really want to specify a maximum width for either TextBox if I can help it.
And here is how I use it in the main test form:
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" ></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition ></RowDefinition>
</Grid.RowDefinitions>
<ctrlLib:RecordingListControl Grid.Row="0" Name="_ctrlRecordings"
PatientIdAndSessionNumber="{Binding PatientIdAndSessionNumberMain, Mode=TwoWay}"
SelectedItem="{Binding SelectedItemMain, Mode=OneWayToSource}" />
<Label Grid.Row="1" Content="{Binding SelectedItemMain.RecordingName}" />
<ctrlLib:NotesControl Grid.Row="2" Name="_ctrlNotes" PatientIdAndSessionNumber="{Binding PatientIdAndSessionNumberMain, Mode=TwoWay}" />
</Grid>
Any ideas? I get the general idea that nothing is telling the TextBox that it's width is constrained so no TextWrapping is invoked, but I'm at a loss as to how to tel the TextBox that there is a width constraint. I've seen all sorts of posts about not using "Auto" and using "*" but nothing seems to work!
Looking ahead, I'm not really happy with how this looks period. I'm currently getting a line drawn around every note item which I don't like. Also, I'd like the textbox where you enter the new note to look like part of the listbox and appear at the bottom.
Thanks,
Dave

What would be an alternative to x:Reference?

I have XAML that looks as follows:
<DataTemplate x:Key="CdTeThickness">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<StackPanel Grid.Row = "0" Orientation="Horizontal">
<CheckBox x:Name="DisplayMarkers" Content="Display Data Points" Margin="8,5,0,5" HorizontalAlignment="Left" IsChecked="False"/>
<CheckBox x:Name="DisplayIndicator" Content="Display Indicator" Margin="8,5,0,5" HorizontalAlignment="Left" IsChecked="False"/>
</StackPanel>
<vf:Chart Grid.Row = "1" Style="{StaticResource chartStyle}" IndicatorEnabled="{Binding Source={x:Reference DisplayIndicator}, Path=IsChecked}">
<vf:Chart.Titles>
<vf:Title Text="{Binding Chart.ChartTitle}"/>
</vf:Chart.Titles>
My understanding is that x:Reference is not widely supported yet. However, this is the only way I was able to bind to the desired property (DisplayIndicator), as shown in the screen shot. Can someone suggest an alternative to x:Reference that will work in this situation?
Often you can use an ElementName binding, however x:Reference is actually well supported.
{Binding IsChecked, ElementName=DisplayIndicator}
Also, as an alternative to direct binding, you could bind both the Checkbox.IsChecked and the Chart.IndicatorEnabled enabled to a property (e.g. ChartDisplayMarkers) on your viewmodel.

Application unable to find resource in Generic.xaml

I am working on a WPF application that uses the Telerik RAD controls for WPF. The application will be used on a PC with a touch screen, so I need to make things like pickers on the DateTimePicker control larger so they can be easily pressed by people with sausage fingers like my own.
I originally used Expression Blend to edit a copy of the control's template. That created a ControlTemplate in the UserControl's XAML file that I was designing. I have another UserControl I'm working on now that will also use the DateTimePicker, so I want to reuse the ControlTemplate.
What I did was I moved the modified template into a new named Style in the project's (a WPF Control Library) Generic.XAML. Here's a short snippet of the Generic.xaml:
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:CarSystem.CustomControls"
xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"
xmlns:Telerik_Windows_Controls_Chromes="clr-namespace:Telerik.Windows.Controls.Chromes;assembly=Telerik.Windows.Controls">
<Style x:Key="RadDateTimePickerControlTemplate1" TargetType="{x:Type telerik:RadDateTimePicker}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type telerik:RadDateTimePicker}">
. . .
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ResourceDictionary>
Here's a snippet of the XAML where I reference the style:
<UserControl x:Class="CarSystem.CustomControls.ReportCriteria"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"
xmlns:cs="clr-namespace:CarSystem.CustomControls"
mc:Ignorable="d"
Height="648"
Width="1117">
<Grid Background="{DynamicResource ContentBackground}">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<GroupBox BorderBrush="Black" FontSize="20" FontWeight="Bold" Grid.Row="0" Header="Report Criteria: " Margin="5">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="320" />
<ColumnDefinition Width="200" />
<ColumnDefinition Width="450" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="110" />
</Grid.ColumnDefinitions>
<GroupBox BorderBrush="Black" FontSize="20" FontWeight="Bold" Grid.Column="0" Header="Date Range:" Margin="5">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="1*" />
<ColumnDefinition Width="2*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<TextBlock FontSize="18"
FontWeight="Bold"
Grid.Column="0"
Grid.Row="0"
HorizontalAlignment="Right"
Text="Start Date: " />
<telerik:RadDateTimePicker FontSize="18"
FontWeight="Bold"
Grid.Column="1"
Grid.Row="0"
Name="StartDatePicker"
Style="{DynamicResource RadDateTimePickerControlTemplate1}" />
<TextBlock FontSize="18"
FontWeight="Bold"
Grid.Column="0"
Grid.Row="1"
HorizontalAlignment="Right"
Text="End Date: " />
<telerik:RadDateTimePicker FontSize="18"
FontWeight="Bold"
Grid.Column="1"
Grid.Row="1"
Name="EndDatePicker"
Style="{DynamicResource RadDateTimePickerControlTemplate1}" />
</Grid>
</GroupBox>
. . .
</GroupBox>
</Grid>
</UserControl>
When I work in Expression Blend, everything looks fine. I see the change in the width of the drop down button for the control. Back in Visual Studio, everything compiles fine, but the change does not show up -- I see the default style for the control only, and the references to the style have a blue squiggly line under them. When you hover the mouse over the squiggly line, the following message is displayed:
The resource "RadDateTimePickerControlTemplate1" cannot be resolved.
The same thing happens if I change "DynamicResource" to "StaticResource" in the XAML. Also, I have made no changes to the Assembly.Info file for the project.
How do I fix this?
Thanks
Tony
As far as I remember you can't have named resources you want to reference in generic.xaml - that you have to put in app.xaml
You have to give the type in key for styles or ComponentResourceKey in key for controltemplates
and in the class static constructor override metadata like:
public class FlatStylebutton : Button
{
static FlatStylebutton()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(FlatStylebutton), new FrameworkPropertyMetadata(typeof(FlatStylebutton)));
}
}
So a solution to your problem could be moving the style to app.xaml
Alternatively you can put it in a separate ResourceDictionary xaml file and import it in ResourceDictionary.MergedDictionaries

WPF Beginner - A simple XAML layout not working as expected

I've just started learning WPF, and followed a book to make this sample calculator application in XAML.
The XAML code is attached below.
I don't have any UI specific code in the xaml.cs file.
However, I'm seeing a difference between design time and runtime. As you can see in the attached screenshot, the upper left button of the calculator is bigger than the rest.
Even more confusingly, the designer when I edit the XAML shows the button correctly.
I've tried to determine why is that, and I'm stumped. Can anyone help?
I'm using VS2008, targeting framework 3.5, if it's any help.
Here's the XAML:
<Window x:Class="TestWpf2008.Calculator"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:TestWpf2008"
Title="Calculator" FontFamily="Calibri" FontSize="15"
SizeToContent="WidthAndHeight" Loaded="Window_Loaded">
<Window.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Dictionary1.xaml"/>
<ResourceDictionary>
<SolidColorBrush x:Key="MyTitleColor" Color="Chocolate" />
<Style TargetType="Button">
<Setter Property="Margin" Value="6"/>
</Style>
</ResourceDictionary>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Window.Resources>
<Grid Background="{StaticResource PrettyBrush}">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
<RowDefinition />
<RowDefinition />
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<TextBlock Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="4" FontSize="24"
Name="Header"
VerticalAlignment="Center" HorizontalAlignment="Center">Calculator</TextBlock>
<TextBox Grid.ColumnSpan="4" Grid.Column="0" Grid.Row="1" Name="Display"
HorizontalContentAlignment="Left" Margin="5" />
<Button Grid.Row="2" Grid.Column="0" Click="Button_Click">7</Button>
<Button Grid.Row="2" Grid.Column="1" Click="Button_Click">8</Button>
<Button Grid.Row="2" Grid.Column="2" Click="Button_Click">9</Button>
<Button Grid.Row="3" Grid.Column="0" Click="Button_Click">4</Button>
<Button Grid.Row="3" Grid.Column="1" Click="Button_Click">5</Button>
<Button Grid.Column="2" Grid.Row="3" Click="Button_Click">6</Button>
<Button Grid.Row="4" Grid.Column="0" Click="Button_Click">1</Button>
<Button Grid.Row="4" Grid.Column="1" Click="Button_Click">2</Button>
<Button Grid.Row="4" Grid.Column="2" Click="Button_Click">3</Button>
<Button Grid.Row="5" Grid.Column="0" Click="Button_Click">0</Button>
<Button Grid.Row="5" Grid.Column="3" Tag="{x:Static local:Operation.PLUS}"
Click="Op_Click">+</Button>
<Button Grid.Row="4" Grid.Column="3" Tag="{x:Static local:Operation.MINUS}"
Click="Op_Click">-</Button>
<Button Grid.Row="3" Grid.Column="3" Tag="{x:Static local:Operation.TIMES}"
Click="Op_Click">*</Button>
<Button Grid.Row="2" Grid.Column="3" Tag="{x:Static local:Operation.DIVIDE}"
Click="Op_Click">/</Button>
<Button Grid.Row="5" Grid.Column="1" >.</Button>
<Button Grid.Row="5" Grid.Column="2" Tag="{x:Static local:Operation.EQUALS}"
Click="Op_Click">=</Button>
</Grid> </Window>
From MSDN
It is legal to define resources within a ResourceDictionary that is specified as a merged dictionary, either as an alternative to specifying Source, or in addition to whatever resources are included from the specified source. However, this is not a common scenario; the main scenario for merged dictionaries is to merge resources from external file locations. If you want to specify resources within the markup for a page, you should typically define these in the main ResourceDictionary and not in the merged dictionaries.
So you just have to move the style out from the merged resourcedictionary
but i suggest that you should
move
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Dictionary1.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
to Application.Resources in App.xaml
keep
<Style TargetType="Button">
<Setter Property="Margin" Value="6"/>
</Style>
in Window.Resources
because thats what you usally would do with merged resourcedictionarys because of the easy reuse between projects of your 'Dictionary1.xaml'

Resources