|
One hack is to use 'initParams' to send these style values to silverlight control. There, you convert them into styles and apply them.
|
|
|
|
|
Hi,
My scenario is like this.
1. I will get the language setting from my settings file.
2. I need to display my control text based on the language setting either in English or other language.
Is it possible to prepare a conditional XAML for the same scenario.
For example:
Can i set the content based on some setting for the Template below
Thanks
|
|
|
|
|
|
Hi,
I have a DatePicker, where I set the CalendarStyle (I'm using mvvm). The issue is, when I select a day on the calender, nothing happens (Looks like the Click event just never fires, or something.)
The Control looks as follow:
<tool:DatePicker Grid.Column="1" Grid.Row="8" SelectedDate="{Binding BirthDate}" CalendarStyle="{DynamicResource CalenderStyleNew}"></tool:DatePicker>
Where the style looks as follow:
<Style TargetType="Controls:Calendar" x:Key="CalenderStyleNew">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Controls:Calendar">
<StackPanel HorizontalAlignment="Center" x:Name="Root">
<Controls:Calendar x:Name="Calendar" SelectedDate="{TemplateBinding SelectedDate}" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}">
<Controls:Calendar.CalendarDayButtonStyle>
<Style>
<Setter Property="Button.Height" Value="50"></Setter>
<Setter Property="Button.Width" Value="50"></Setter>
<Setter Property="Button.FontSize" Value="20"></Setter>
</Style>
</Controls:Calendar.CalendarDayButtonStyle>
<Controls:Calendar.CalendarButtonStyle>
<Style>
<Setter Property="Button.Height" Value="50"></Setter>
<Setter Property="Button.Width" Value="50"></Setter>
<Setter Property="Button.FontSize" Value="20"></Setter>
</Style>
</Controls:Calendar.CalendarButtonStyle>
</Controls:Calendar>
</StackPanel>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
I need the buttons bigger, because it's a touch screen app... Test this in your app, and you'll see, nothing happens when you select a day...
Any help would be much appreciated.
Kind regards,
Hugo
|
|
|
|
|
ok, after A LOT of struggling, I managed to make a work around... but, it's not pretty !!! An easier solution would be much appreciated.
What I did, was the following:
<Controls:DatePicker Grid.Column="1" Grid.Row="6" SelectedDate="{Binding BirthDate}" ViewModels:EmployeeViewModel.DatePickerGotFocus="{Binding}">
<Controls:DatePicker.CalendarStyle>
<Style TargetType="Controls:Calendar">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Controls:Calendar">
<StackPanel HorizontalAlignment="Center" x:Name="Root">
<Controls:Calendar x:Name="Calendar" ViewModels:EmployeeViewModel.OnCalenderLoaded="{Binding}" SelectedDate="{Binding BirthDate}" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}">
<Controls:Calendar.CalendarDayButtonStyle>
<Style>
<Setter Property="Button.Height" Value="50"></Setter>
<Setter Property="Button.Width" Value="50"></Setter>
<Setter Property="Button.FontSize" Value="20"></Setter>
</Style>
</Controls:Calendar.CalendarDayButtonStyle>
<Controls:Calendar.CalendarButtonStyle>
<Style>
<Setter Property="Button.Height" Value="50"></Setter>
<Setter Property="Button.Width" Value="50"></Setter>
<Setter Property="Button.FontSize" Value="20"></Setter>
</Style>
</Controls:Calendar.CalendarButtonStyle>
</Controls:Calendar>
</StackPanel>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Controls:DatePicker.CalendarStyle>
</Controls:DatePicker>
Then I made attached properties for the DatePicker and Calendar as follow:
private Calendar _calender;
private DatePicker _datePicker;
public static object GetDatePickerGotFocus(DependencyObject obj)
{
return (object)obj.GetValue(DatePickerGotFocusProperty);
}
public static void SetDatePickerGotFocus(DependencyObject obj, object value)
{
obj.SetValue(DatePickerGotFocusProperty, value);
}
public static readonly DependencyProperty DatePickerGotFocusProperty =
DependencyProperty.RegisterAttached("DatePickerGotFocus", typeof(object), typeof(EmployeeViewModel), new UIPropertyMetadata(OnDatePickerGotFocus));
private static void OnDatePickerGotFocus(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
DatePicker datePicker = d as DatePicker;
EmployeeViewModel model = e.NewValue as EmployeeViewModel;
if (datePicker != null && model != null)
{
model._datePicker = datePicker;
}
}
public static object GetOnCalenderLoaded(DependencyObject obj)
{
return (object)obj.GetValue(OnCalenderLoadedProperty);
}
public static void SetOnCalenderLoaded(DependencyObject obj, object value)
{
obj.SetValue(OnCalenderLoadedProperty, value);
}
public static readonly DependencyProperty OnCalenderLoadedProperty =
DependencyProperty.RegisterAttached("OnCalenderLoaded", typeof(object), typeof(EmployeeViewModel), new UIPropertyMetadata(OnCalenderLoaded));
private static void OnCalenderLoaded(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
Calendar calendar = d as Calendar;
EmployeeViewModel model = e.NewValue as EmployeeViewModel;
if (calendar != null && model != null)
{
model._calender = calendar;
}
}
And then I set the visibility as follows:
public DateTime _birthDate;
public DateTime BirthDate
{
get { return _birthDate; }
set
{
_birthDate = value;
OnPropertyChanged("BirthDate");
if (_calender != null)
{
_calender.Visibility = Visibility.Hidden;
_datePicker.GotFocus += new RoutedEventHandler(_datePicker_GotFocus);
}
}
}
private void _datePicker_GotFocus(object sender, RoutedEventArgs e)
{
_calender.Visibility = Visibility.Visible;
etc..
|
|
|
|
|
lol, I over complicated this a bit. The final solution I made was as follow:
<tool:DatePicker Grid.Column="1" Grid.Row="8" SelectedDate="{Binding BirthDate}" ViewModels:PatronViewModel.DatePickerGotFocus="{Binding}" Height="34" FontSize="18">
<tool:DatePicker.LayoutTransform>
<ScaleTransform ScaleY="1.5" ScaleX="1.5"></ScaleTransform>
</tool:DatePicker.LayoutTransform>
<tool:DatePicker.CalendarStyle>
<Style TargetType="tool:Calendar">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="tool:Calendar">
<StackPanel HorizontalAlignment="Center" x:Name="Root">
<tool:Calendar x:Name="Calendar" ViewModels:PatronViewModel.OnCalenderLoaded="{Binding}" SelectedDate="{Binding BirthDate}" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}">
<tool:Calendar.LayoutTransform>
<ScaleTransform ScaleX="2" ScaleY="2"></ScaleTransform>
</tool:Calendar.LayoutTransform>
</tool:Calendar>
</StackPanel>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</tool:DatePicker.CalendarStyle>
</tool:DatePicker>
So by simply scaling the DatePicker, I got a cool touch screen DatePicker....
|
|
|
|
|
I tried your code above. For some reason, when I select a date from the calendar popup, it doesn't close the popup or select a date. I removed all Bindings since I don't have a viewmodel. I am just trying this out before putting it in my project.
|
|
|
|
|
I remember having this problem.... I had to do some magic on the actual date time by hiding and showing the actual boxes....
|
|
|
|
|
I have the same problem (selecting date does nothing and I am not using view model) I was hoping you could elaborate on the "magic" that you used to resolve this problem. Thanks.
|
|
|
|
|
You don't even want to know what I had to do to fix this !!!! It's INSANE !
|
|
|
|
|
hi bonkers,
i thank you very much!!!!.
your snippet helps me to solve my DatePicker SelectedDate - Binding problem!
here is my solution. just override the ControlTemplate of the DatePicker-Control and bind the SelectedDate of the PopupCalendar.
<Popup Name="Part_CalendarPopup"
Margin="0,22,-22,-12"
HorizontalAlignment="Right"
PlacementTarget="{Binding ElementName=Part_CalendarButton}" StaysOpen="False">
<Grid Name="Part_CalendarGrid" Background="White">
<cal:Calendar
SelectedDate="{Binding SelectedDate, Mode=TwoWay}" <!-- the holy line -->
Height="160" Width="160"
FooterVisibility="Collapsed" WeekColumnVisibility="Collapsed"
FontSize="9"/>
</Grid>
</Popup>
|
|
|
|
|
Hi.. Inside my code the combobox is not responding to key press events.. like if user presses M, combobox should select Marrylands in the dropdownlist like the ASP .net combobox does. Can anyone please help???
<ComboBox HorizontalAlignment="Right" Height="23" Name="cmbPortsFrom" KeyDown="cmbPortsFrom_KeyDown" Width="105" SelectedIndex="0" Grid.Row="2" Grid.Column="0" >
<ComboBox.ItemsPanel>
<ItemsPanelTemplate>
<VirtualizingStackPanel />
</ItemsPanelTemplate>
</ComboBox.ItemsPanel>
<ComboBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Path=Code}" FontSize="15" Height="20"/>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
codebehind:
Dim lDataSource2 As ICollection(Of BusinessLayer.Ports)
lDataSource2 = mBalObjPorts.getPortData()
Me.cmbPortsFrom.ItemsSource = lDataSource2
|
|
|
|
|
SR81 wrote: KeyDown="cmbPortsFrom_KeyDown"
What are you doing in the keydown event ?
|
|
|
|
|
apparently nothing, its an empty function.I believe the combobox should automatically select Marrylands from the list if user presses "M" key??
|
|
|
|
|
Perhaps your empty event is preventing this from occuring ?
Christian Graus
Driven to the arms of OSX by Vista.
"! i don't exactly like or do programming and it only gives me a headache." - spotted in VB forums.
I can do things with my brain that I can't even google. I can flex the front part of my brain instantly anytime I want. It can be exhausting and it even causes me vision problems for some reason. - CaptainSeeSharp
|
|
|
|
|
I have removed the function, still its not working.
It could be because the combobox contains nearlly 500 rows?
Anyhow i am writing the keypress event function to achieve this. Thanks.
|
|
|
|
|
SR81 wrote: It could be because the combobox contains nearlly 500 rows?
That doesn't seem logical.
Perhaps because changes to VisualTree will be making it difficult to decide what to use as SelectedValuePath. Just a guess.
|
|
|
|
|
If you are going to use a just a TextBox then do it this way,
<ComboBox x:Name="myComboBox" IsEditable="true" DisplayMemberPath="Code" Height="266" >
<ComboBox.ItemsPanel>
<ItemsPanelTemplate>
<VirtualizingStackPanel />
</ItemsPanelTemplate>
</ComboBox.ItemsPanel>
</ComboBox>
If no, you would have to implement the functionality on KeyDown event (specifically by overriding OnPreviewKeyDown). This[^] might be of help.
|
|
|
|
|
Thanks,that just gave me an idea of creating an AJax listsearch extender kind of control in WPF. Cheers
|
|
|
|
|
I have so many questions I don't know where to begin. I'll just throw out one of my questions. Suppose I have multiple modeless instances of the same window class active at the same time. Say there's a Grid called metadataGrid in the window, and I want different data values in each of the different instances of the same window class. How do I express the data binding in XAML?
Let's say I have a List<PhotoMetadata> called PhotoMetadataList that contains the data I want to display in the grid. PhotoMetadata is derived from INotifyPropertyChanged and so metadataGrid should get notified every time I make a change to a property in PhotoMetadata.
Each window instance has its own instance of List<PhotoMetadata> , say for a different photograph. Let's say the name of the window is PhotoInformationWindow. I started with the following XAML in my Window.Resources (irrelevant details omitted):
x:Key="metadata"<br />
Source="{Binding Mode=OneWay, RelativeSource={RelativeSource AncestorType=local:PhotoInformationWindow}, <br />
Path=PhotoMetadataList}"
Then in my metadataGrid XAML, I have this line:
ItemsSource="{Binding Source={StaticResource metadata}}"
But metadataGrid just ignores any data I write to PhotoMetadataList, even when there's only a single instance of the window. I should think this would work for not just a single instance of PhotoInformationWindow, but for multiple instances. I hope someone can straighten out my thinking and point out some obvious errors I'm making.
|
|
|
|
|
fjparisIII wrote: Say there's a Grid called metadataGrid in the window, and I want different data values in each of the different instances of the same window class. How do I express the data binding in XAML?
Each window will need a different data source, representing the data you want to bind to. Don't get too stuck on XAML, use code if it's easier/works better.
I would step back from what you're doing and set the source in code first, then make sure that works, then move towards XAML if you must. It removes a layer of abstraction and lets you focus on getting each step working.
Christian Graus
Driven to the arms of OSX by Vista.
"! i don't exactly like or do programming and it only gives me a headache." - spotted in VB forums.
I can do things with my brain that I can't even google. I can flex the front part of my brain instantly anytime I want. It can be exhausting and it even causes me vision problems for some reason. - CaptainSeeSharp
|
|
|
|
|
Christian Graus wrote: Each window will need a different data source, representing the data you want to bind to.
I guess I didn't make it clear that each window does have a different data source. Each window uses the same class for the data source, but a different instance of that class.
Christian Graus wrote: I would step back from what you're doing and set the source in code first, then make sure that works, then move towards XAML if you must.
Interesting. This is the opposite advice you get from MSDN, books, and vendors of 3rd party controls like Xceed. None of those sources want you in code to do stuff like this. It seems as if code is going against the grain of the WPF architecture.
Personally, I'd like a programmable interface that lets you specify the number of rows and columns and then set the value of each cell by row and column indexes. All this data-binding crap requires a whole new outlook and knowledge of an infrastructure that wasn't necessary back in the "good old days" of MFC. On the other hand, once the data binding is set up, everything is supposed to work auto-magically. The problem is acquiring the massive understanding of the data binding infrastructure, and to use it at all, you have to know the whole thing like the back of your hand.
|
|
|
|
|
I feel I have not understood your question.
fjparisIII wrote: Then in my metadataGrid XAML, I have this line:
ItemsSource="{Binding Source={StaticResource metadata}}"
Grid does not have an ItemsSource property.
fjparisIII wrote: x:Key="metadata"
Source="{Binding Mode=OneWay, RelativeSource={RelativeSource AncestorType=local:PhotoInformationWindow},
Path=PhotoMetadataList}"
Another way is setting DataContext of PhotoInformationWindow to the respective PhotoMetadataList.
|
|
|
|
|
ABitSmart wrote: Grid does not have an ItemsSource property.
Sorry about that. I was trying to keep things in terms of familiar Microsoft WPF classes. I should have use ListView in my example. I'm actually using a 3rd party control, but their tech support response to questions is not timely and they seem to get impatient when you're not an MFC/XAML guru when it comes to using their controls. They only want questions specifically about their implementations. But their control is fundamentally rooted in WPF, down to the core, so things like ItemSource are fundamental to their design. They seem to want to answer questions only if you bring utterly exhaustive knowledge of WPF/XAML to the table, as if to say, what are you doing spending $1,000 on our control if you can't write a book on WPF/XAML? (Actually I have their free, Standard Edition, which actually costs $300 now, but I got in early enough to still qualify for free upgrades.)
|
|
|
|
|
Ok. So, data is displaying correctly just the updates you make to PhotoMetadataList are not getting propogated to PhotoInformationWindow ?
Updates(CollectionChanged/PropertyChange?) are done in PhotoInformationWindow itself or in the Parent Window ?
Well, any DataBinding errors in the Output window ?
If my questions seem relevant then,
How about setting PhotoMetadataList as the DataContext of PhotoInformationWindow instead of accessing it as a StaticResource ? After setting it as the DataContext of PhotoInformationWindow bind ListView's ItemsSource using RelativeSource binding.
I would certainly try attempting this with a WPF ListView (if its a similar model) before making frustrating attempts with the third party control vendor.
|
|
|
|