I've a strange issue with my monthpicker. It has a huge width at initialization.
I'm using MVVM Light Toolkit and it seems that's causing the issue.
Indeed, with a standard WPF application, the same code works...
Another hint, without the popup control, this code works with MVVM Light Toolkit.
Here is my code:
<Window x:Class="MvvmLight1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
SizeToContent="WidthAndHeight"
Title="MVVM Light Application"
DataContext="{Binding Main, Source={StaticResource Locator}}">
<Grid>
<Popup IsOpen="{Binding ElementName=btn, Path=IsChecked}" StaysOpen="False" >
<Calendar x:Name="_calendar"
Loaded="_calendar_OnLoaded"
DisplayModeChanged="_calendar_DisplayModeChanged"
DisplayMode="Month" />
</Popup>
<ToggleButton Height="50" Width="100" Content="Click me" x:Name="btn" ClickMode="Release"/>
</Grid>
And here is the code Behind:
using System.Windows;
using MvvmLight1.ViewModel;
using System.Windows.Controls;
namespace MvvmLight1
{
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void _calendar_DisplayModeChanged(object sender, CalendarModeChangedEventArgs e)
{
_calendar.DisplayMode = CalendarMode.Year;
}
private void _calendar_OnLoaded(object sender, RoutedEventArgs e)
{
_calendar.DisplayMode = CalendarMode.Year;
}
}
}
Nothing fancy... I'm struggling with it for a while now.. Any help would be appreciated!
Thanks in advance!