Hello,
this is the picture:
I have a solution with SILVERLIGHT/WPF shared code and, whenever possible, I use shared UserControls in the 2 projects.
I use my own custom dialogs (AppointmentDialogFactory : ScheduleDialogFactoryBase) in order to show a customize window to the user inserting a new appointment or updating an existing one.
Since I want to use shared code my custom dialogs are UserControls.
Now, while I managed to do everything I wanted to, I am missing 2 things:
1) I don't know how to set width and height of the hosting window (yours) , since your window does not take in account the usercontrol dimensions (which I set to my needs).
2) When I'm done with the new appointment how to I close your window?
I guess it's something silly, but ... I'm lost.
Best Regards
Roberto
Hi Roberto,
I'm looking into your requirements and I'm going to put together a sample to test with. I should have something for you early next week. Also I noticed you created another thread here:https://www.infragistics.com/community/forums/f/ultimate-ui-for-wpf/68808/how-do-i-close-a-custom-appointment-dialog-and-return-to-the-calling-xamoutlookcalendarview
I'm going to handle both of these issues in this thread so we don't have two active threads on the same topic.
Sorry for the delay. Here is a sample I put together that demonstrates how you can create custom appointment dialogs and properly closing them once you've finished modifying your data. This code functions 100% across both Silverlight and WPF and I've included samples for both platforms. The code is basically the same.
In my sample I created a new Appointment factory and AppointmentDialogCore objects. Using an AppointmentDialogCore instead of a UserControl will give you access to various commands you can fire off that can save and close the dialog window. I then created a style that targets my custom dialog core object. This style is templated to look the way I want. This style works for both SL and WPF mind you so you only need to write this once. In the style is where I place the command code that will close the window upon a button press.
I'm still looking into the window resizing and I'll update you on my progress for that tomorrow.
Hi Rob,thanks for your sample which is very appropriate and clear. I have a doubt though.Say I need to bind a property in the template:
<ListBox ItemsSource="{Binding Path=AutoCompleteItems, Mode=TwoWay}" SelectedItem="{Binding Path=SelectedAutoCompleteItem, Mode=TwoWay}"></ListBox>Before your sample I would say in the code of my UserControl:DataContext = new NewAppointmentViewModel();
where the NewAppointmentViewModel class implements INotifyPropertyChanged and has the AutoCompleteItems property.
How do I DataBind to my own custom properties?Should I implement INotifyPropertyChanged in the CustomAppointmentDialogCore class and put those properties there?
For this you will need to use the following syntax for your bindings:
"{Binding RelativeSource={RelativeSource TemplatedParent}, Path=AutoCompleteItems, Mode=TwoWay}"
For modifying the dimensions of the parent dialog, you're going to need some platform specific code. Silverlight and WPF use different dialog window controls from each other and they both function a bit differently. The Silverlight schedule control uses a XamDialogWindow as the parent dialog and WPF uses a ToolWindow.
For Silverlight, in the AppointmentDialogCore's OnApplyTemplate override, you can grab the dialog window by traversing up the visual tree until you find the DialogRootPanel element. This object has a property called DialogWindow that you can use to set the width and height of the parent window.
For WPF things are a bit different. The timing of the dialog creation doesn't allow you to change the ToolWindow's dimensions in OnApplyTemplate as it will be reset to default right after. We could use a dispatcher to delay this but you'll end up with a dialog window that flashes for a split second as a large window before it changes to your desired size. In order to avoid this I use the ToolWindow's SizeChanged event and Loaded event to keep setting the dimensions to what I want until the window finishes loading. This way when the window is set to it's default size, I set it to the size I want instead through the SizeChanged event. Check out the sample to see this in more detail.