|
Kevin Marois wrote: an action for each link Exactly, but it seems that you just happened to use the correct word. System.Action is the class to use, or (more typical in WPF) a Command object (take a look at the Command Pattern ). When the link is clicked, you call the Invoke() method of the Action object.
|
|
|
|
|
Hi ,
I am currently developing an application but I need to have to switch between two languages , but I can't do it .
In fact , I created two Resources files for both languages and I set them to public and then then I put the propertie to Static as mentioned in many tutorials .
Thank you so much for your help.
My code written :
App.xaml.cs
public App()
{
if (Presentation.ViewModels.LoginWindow.LanguageSelect != null)
{
if (Presentation.ViewModels.LoginWindow.LanguageSelect.Equals("Italian"))
{
System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("it-IT");
}
else
{
System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("fr-FR");
}
}
else
{
Console.WriteLine("Verify the choosig langa=uage!");
}
}
ViewModel:
private string selectedLanguage;
public static string LanguageSelect;
public string SelectedLanguage
{
get
{
return selectedLanguage;
}
set
{
selectedLanguage = value;
RaisePropertyChanged("SelectedLanguage");
LanguageSelect = selectedLanguage.ToString();
}
}
And I the view.xaml
<ComboBox x:Name="MyCombo" Height="23" Width="90" HorizontalAlignment="Right" ItemsSource="{Binding Languages}" SelectedItem="{Binding SelectedLanguage, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" VerticalAlignment="Top" Margin="20" IsEditable="False" Background="DarkCyan" Foreground="Blue"></ComboBox>
|
|
|
|
|
I have a treeview bound to a collection of Employees. Each Employee has one or more HoursWorked entity in a property called HoursWorked.
The HierarchicalDataTemplate has an Add button in it to add a new Hours Worked node under it.
Each hours worked node DataTemplate has a Remove button next to it. When it's clicked I'd like to pass both the Employee and the HoursWorked entity.
So I have:
<!--Employee-->
<HierarchicalDataTemplate DataType="{x:Type models:WorkDoneEmployeeInfoModel}"
ItemsSource="{Binding HoursWorked}">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="60"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<TextBlock Grid.Column="0"
Text="Employee:"
VerticalAlignment="Center"
FontWeight="Bold"/>
<TextBlock Grid.Column="1"
VerticalAlignment="Center"
Text="{Binding EmployeeName}"/>
<Button Grid.Column="2"
Command="{Binding RelativeSource={RelativeSource AncestorType={x:Type UserControl},Mode=FindAncestor},Path=DataContext.AddHoursCommand}"
CommandParameter="{Binding}"
VerticalAlignment="Center"
Height="22"
Width="22"
Margin="10,3,3,3">
<Image Source="/FMG.UI.WPF.Shared;component/Media/Images/add_256.png"
Height="16"
Width="16"/>
</Button>
</Grid>
</HierarchicalDataTemplate>
<!--Hours Worked-->
<DataTemplate DataType="{x:Type models:WorkDoneHoursWorkedModel}">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="100"/>
<ColumnDefinition Width="250"/>
<ColumnDefinition Width="100"/>
<ColumnDefinition Width="250"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<TextBlock Grid.Column="0"
Text="Time In:"
VerticalAlignment="Center"
FontWeight="Bold"/>
<TextBlock Grid.Column="1"
VerticalAlignment="Center"
Text="{Binding WorkStartDateTime}"/>
<TextBlock Grid.Column="2"
VerticalAlignment="Center"
Text="Time Out:"
FontWeight="Bold"/>
<TextBlock Grid.Column="3"
VerticalAlignment="Center"
Text="{Binding WorkEndDateTime}"/>
<Button Grid.Column="3"
Command="{Binding RelativeSource={RelativeSource AncestorType={x:Type UserControl},Mode=FindAncestor},Path=DataContext.SubtractHoursCommand}"
VerticalAlignment="Center"
Height="22"
Width="22"
Margin="10,3,3,3">
<Button.CommandParameter>
<MultiBinding Converter="{StaticResource MyMultiConverter}">
<!--The EmplyeeEntity-->
<Binding Path=""/> <===== WHAT GOES HERE? ===========
<!--The HoursWorked entity-->
<Binding Path="{Binding}"/>
</MultiBinding>
</Button.CommandParameter>
<Image Source="/FMG.UI.WPF.Shared;component/Media/Images/subtract_256.png"
Height="16"
Width="16"/>
</Button>
</Grid>
</DataTemplate >
So in the bottom template, I am passing the WoursWorked entity, but how do I set up the XAML to pass the parent node?
Thank you
[EDIT - RESOLVED]
<Button.CommandParameter>
<MultiBinding Converter="{StaticResource multiValueConverter}">
<Binding RelativeSource="{RelativeSource AncestorType={x:Type TreeViewItem}, AncestorLevel=2}"/>
<Binding RelativeSource="{RelativeSource AncestorType={x:Type TreeViewItem}, AncestorLevel=1}"/>
</MultiBinding>
</Button.CommandParameter>
If it's not broken, fix it until it is
modified 2-May-14 18:04pm.
|
|
|
|
|
I have a DP called FullName. When it changes, I need to parse it and add it to an instance property of type List<<string>> FileAsOptions.
So, when I have
"Joe Smith"
or
"Smith, Joe"
they both get added to the list property.
The FullName property is a DP, and the FileAsOptions is an instance property. It's not a DP because I don't want it to be bindable.
So the FullName DP's change callback calls a private method that parses the name and add it to the instance list
The problem is that the instance property needs to call RaisePropertyChanged, which only works on instance properties. So the property cannot be static.
Here's the code:
public partial class ContactCard : _UserControlBase
{
public ContactCard()
{
InitializeComponent();
LayoutRoot.DataContext = this;
}
private List<string> _FileAsOptions;
public List<string> FileAsOptions
{
get { return _FileAsOptions; }
set
{
if (_FileAsOptions != value)
{
_FileAsOptions = value;
RaisePropertyChanged("FileAsOptions");
}
}
}
public string FullName
{
get { return (string)GetValue(FullNameProperty); }
set { SetValue(FullNameProperty, value); }
}
public static readonly DependencyProperty FullNameProperty = DependencyProperty.Register(
"FullName", typeof(string), typeof(ContactCard),
new FrameworkPropertyMetadata("", new PropertyChangedCallback(OnFullNamePropertyChanged)));
private static void OnFullNamePropertyChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
{
var card = sender as ContactCard;
}
private void setFileAsOptions(string fullName)
{
FileAsOptions = new List<string>();
if (!string.IsNullOrEmpty(fullName))
{
string[] words = fullName.Split(' ');
if (words.Length == 1)
{
FileAsOptions.Add(words[0]);
}
if (words.Length == 2)
{
FileAsOptions.Add(string.Format("{0} {1}", words[0], words[1]));
FileAsOptions.Add(string.Format("{0}, {1}", words[1], words[0]));
}
}
}
}
In summary, I need to be able to call the setFileAsOptions from the DP, which is static.
What's the right approach here?
If it's not broken, fix it until it is
|
|
|
|
|
Unless I've misread your question, it's quite simple!
private static void OnFullNamePropertyChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
{
var card = sender as ContactCard;
card.setFileAsOptions((string)e.NewValue);
}
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
LOL. I must be totally blind.. It's been a long day already.
Thanks!
If it's not broken, fix it until it is
|
|
|
|
|
I am creating a user control. I will be using this user control in a few different apps. Once it's done I'll include its assembly in my project, reference it, and use it in my XAML somewhere. Pretty standard.
The question is... How do I apply a different set of styles to it based on the app I'm in?
Thanks
If it's not broken, fix it until it is
|
|
|
|
|
The simplest way to achieve this is to have application level themes. In other words, in App A - you would set the styles for your control to be the ones you want in App A; in App B you set the styles for the control based on the ones you want in App B, and so on. Make sure you have a default theme for your control in place as well.
|
|
|
|
|
Ok, so create a theme. Isn't a theme just a collection of styles?
If it's not broken, fix it until it is
|
|
|
|
|
|
Hi Kevin,
Sorry for late reply to your post.
1.You can create a seperate styles for appA, Appb... and apply the theme accordingly as a staticresource.
2.Suppose in same application you want different theme based on some action then just use the above mentioned idea and apply themes using Dynamicresource.
Thanks.
|
|
|
|
|
I don't know why I can't get this to work...
In class A I have
public delegate void LoggingDelegate(string message);
and
public void LogMessage(string message)
{
}
then I want to pass it to class B, so I have:
LoggingDelegate logMessageHandler = LogMessage;
ClassB.SomeMethod(logMessageHandler);
Then in ClassB I have
public void SomeMethod(Delegate logDelegate)
{
logDelegate.
}
WHat's wrong here?
Thanks!
If it's not broken, fix it until it is
|
|
|
|
|
All ClassB.SomeMethod knows is that logDelegate is a Delegate , not that it is LoggingDelegate .
At least the way you have shown it.
So the IntelliSense knows only that as well.
|
|
|
|
|
I am trying to hide a text block. When a Checkbox is checked, it should be hidden. When it's unchecked the textblock should be visible.
The checkbox is bound to an object called SelectedProcess. If SelectedProcess is null, the textblock should be hidden.
Here's my XAML:
<CheckBox IsChecked="{Binding SelectedProcess.Enabled}"
IsEnabled="{Binding AllowProcessEdit}"
x:Name="EnabledCheckbox"
Foreground="Black"
FontSize="12"
Margin="10,0,0,0"
VerticalAlignment="Center"
HorizontalAlignment="Stretch"/>
<TextBlock Grid.Row="4"
Foreground="Red"
FontWeight="Bold"
FontSize="12"
VerticalAlignment="Center"
HorizontalAlignment="Right"
Text="This process is disabled"
Margin="10,0,0,0">
<TextBlock.Style>
<Style>
<Style.Triggers>
<DataTrigger Binding="{Binding SelectedProcess}" Value="Null">
<Setter Property="UIElement.Visibility" Value="Hidden"/>
</DataTrigger>
<DataTrigger Binding="{Binding SelectedProcess.Enabled}" Value="True">
<Setter Property="UIElement.Visibility" Value="Hidden"/>
</DataTrigger>
<DataTrigger Binding="{Binding SelectedProcess.Enabled}" Value="False">
<Setter Property="UIElement.Visibility" Value="Visible"/>
</DataTrigger>
</Style.Triggers>
</Style>
</TextBlock.Style>
</TextBlock>
It works when SelectedProcess is NOT null, but when SelectedProcess IS null, the text is still visible.
What am I doing wrong here?
Thanks
If it's not broken, fix it until it is
|
|
|
|
|
|
That did it. Thank you!
If it's not broken, fix it until it is
|
|
|
|
|
Your issue seems fixed, which is great.
However, I wonder why you use datatriggers to accomplish this.
Consider doing it through binding instead with the help of a converter.
If the visibility of the texblock is always directly related to the checkbox being checked / unchecked, then you could use elementbinding to do so.
<TextBlock Visibility="{Binding IsChecked, Converter={StaticResource boolToVisibilityConverter}, ElementName=CheckBoxName}" />
The resulting XAML is simpler and achieves the same result.
|
|
|
|
|
Hi. i have one question.
I would like to specify the area to zoom in (ex . fence -> rect type )
well. i saw seadragon open source but i can't understand fitBounds Method
too hard viewportOrigin & viewportWidth
how can i calculation multiscaleImage viewport with two points
and make fit bound feature
please help me.
note ) i don't use map control. only multiscaleImage
|
|
|
|
|
I'm trying set focus to a UI element from within a view model.
First, following this example[^] I created the Attached Property.
Then in my VM I created a bool property called "IsHourlyMinutesFocused":
private bool _IsHourlyMinutesFocused;
public bool IsHourlyMinutesFocused
{
get { return _IsHourlyMinutesFocused; }
set
{
if (_IsHourlyMinutesFocused != value)
{
_IsHourlyMinutesFocused = value;
RaisePropertyChanged("IsHourlyMinutesFocused");
}
}
}
Next, I added it to the XAML:
<TextBox Grid.Row="0"
Grid.Column="2"
VerticalAlignment="Center"
classes:FocusExtension.IsFocused="{Binding IsHourlyMinutesFocused}"
Focusable="True"
Text="{Binding SelectedProcess.ProcessSchedule.HourlyMinutes}"
Margin="2,0,2,0"
Width="40"/>
When I set IsHourlyMinutesFocused = true, nothing happens. The OnIsFocusedPropertyChanged event in the DP never fires.
What's wrong here?
If it's not broken, fix it until it is
|
|
|
|
|
Hi ,
I am new in coding WPF MVVM apps.
My question is how to change le language using a combobox at Runtime.
I tried the static resources and it worked well , but trying to change it Runtime using Threading.thread class didn't work.
Is there any possibility to solve that problem.
Thanks a lot for your help.
|
|
|
|
|
This is now the FOURTH time you have asked the same question.
DO NOT repost the same question. It won't get your question answered any quicker; if anything, it will just annoy the people who would otherwise be trying to help you, and result in all of your questions being ignored.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
|
Hi ,
I need to change culture mainly between two languages ; italian and English using the Combobox in WPF MVVM.
I tried to databind the ViewModel with my Mainview but I didn't succeed.
I will be so thankful if someone could help.
Here is my Combobox declaration in xaml :
<ComboBox IsEditable="True" Text="Language" HorizontalAlignment="Right" VerticalAlignment="Top" Width="95" Margin="34,21,34,0" ItemsSource="{Binding Languages}" SelectedItem="{Binding SelectedLanguage, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Foreground="#FF434C64" removed="Green" Height="24.96" />
Here is View Model definition :
public void ChangeLanguage()
{
if (SelectedLanguage == "en")
{
Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("en");
}
else
if (SelectedLanguage == "it-IT")
{
Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("it-IT");
}
}
Here the declaration within the construcor of my View Model
public ViewModel()
{
LoadData();
ChangeLanguage();
Login = new DelegateCommand(this.Logging, delegate()
{
return (!String.IsNullOrEmpty(Username) && !String.IsNullOrEmpty(Password) && !String.IsNullOrEmpty(Email));
});
Register = new DelegateCommand(this.Registering, delegate()
{
return (!String.IsNullOrEmpty(Username) && !String.IsNullOrEmpty(Password) && !String.IsNullOrEmpty(Email));
});
|
|
|
|
|
Where is your SelectedLanguage property declaration? What does it look like?
|
|
|
|
|
I am implementing scrollable text in a custom control. Each line of text has its own Visual. In the simple case of horizontal scrolling, I replace the Transform of each Visual to produce the desired effect. The scroll bar moves, but the text does not. Am I missing a step that causes the new Transform objects to be reflected (presumably as parameter changes) in the Composition Tree?
Ron Martin
|
|
|
|