|
In your CanCreateRole method, validate the input, and return false if the input is not valid.
In your CreateRole method, call CanCreateRole to validate the input, and if it's not valid, don't close the dialog.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
But this did'nt solve my problem
because what I need is :
- let user enter some data (if no data => the button still disabled related to
CanCreateRole - when there is data click on Button "OK"
- if the data are valid against condition we do nothing and the DialogService close (normal behavior)
ELSE (data not valid ) we display messagebox and the DialogService is still shown with last data entered.
|
|
|
|
|
So do your extra validation in the CreateRole method, and don't close the dialog if it fails.
Or are you saying that the dialog always closes after invoking the command? If that's the case, we'll need to know what the implementation of your dialog service looks like.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
the code of command is as described in the first question :
var createCommand = new UICommand
{
Id = MessageBoxResult.OK,
Caption = Properties.Resources.CstOk,
IsCancel = false,
IsDefault = true,
Command = new DelegateCommand(CreateRole, CanCreateRole)
};
|
|
|
|
|
Yes, but we can't see your dialog service code.
If it's something you've written, then you need to show the relevant parts of the code.
If it's something you got from an article or GitHub project, then we'll need a link to the source.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
In my MainWindow.xaml (which will validate data after click on OK )
<pre> <dxmvvm:Interaction.Behaviors>
<dx:DXMessageBoxService />
<dxmvvm:CurrentWindowService Window="{Binding RelativeSource={RelativeSource AncestorType={x:Type Window}, Mode=FindAncestor}}" />
<dx:DialogService DialogWindowStartupLocation="CenterOwner" Name="RoleServiceDialog">
<dx:DialogService.ViewTemplate>
<DataTemplate>
<views:Role_View></views:Role_View>
</DataTemplate>
</dx:DialogService.ViewTemplate>
</dx:DialogService>
</dxmvvm:Interaction.Behaviors>
in MainWindow.cs (the ViewModel related to the MainWindow.xaml)
_roleViewModel = new Role_ViewModel(eTypeOperation);
var createCommand = new UICommand
{
Id = MessageBoxResult.OK,
Caption = Properties.Resources.CstOk,
IsCancel = false,
IsDefault = true,
Command = new DelegateCommand(CreateRole, CanCreateRole)
};
var cancelCommand = new UICommand
{
Id = MessageBoxResult.Cancel,
Caption = Properties.Resources.CstCancel,
IsCancel = true,
IsDefault = false,
};
RoleService.ShowDialog(new List<UICommand> { createCommand, cancelCommand},Properties.Resources.CstNewRole, _roleViewModel);
private void CreateRole()
{
_roleViewModel.AcceptChanges();
if (ValidateData(_roleViewModel.RoleName.Trim()))
{
AddRole(_roleViewModel.RoleName, _roleViewModel.RoleDescription);
}
}
private bool CanCreateRole()
{
return !string.IsNullOrEmpty(_roleViewModel.RoleName.Trim());
}
|
|
|
|
|
So you're using the DevExpress MVVM framework?
Looking at the documentation[^], your command can take a CancelEventArgs parameter to allow it to keep the dialog open:
Note that dialog commands take a CancelEventArgs object as a parameter. When dialog commands are invoked, the dialog is closed by default. To prevent this behavior, it is necessary to set the CancelEventArgs.Cancel parameter to True.
var createCommand = new UICommand
{
Id = MessageBoxResult.OK,
Caption = Properties.Resources.CstOk,
IsCancel = false,
IsDefault = true,
Command = new DelegateCommand<CancelEventArgs>(CreateRole, CanCreateRole)
};
private bool CanCreateRole(CancelEventArgs e)
{
return !string.IsNullOrWhiteSpace(_roleViewModel.RoleName);
}
private void CreateRole(CancelEventArgs e)
{
_roleViewModel.AcceptChanges();
if (ValidateData(_roleViewModel.RoleName.Trim()))
{
AddRole(_roleViewModel.RoleName, _roleViewModel.RoleDescription);
}
else
{
e.Cancel = true;
}
}
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Great, saved me
|
|
|
|
|
I'm fairly to WPF and C# and slowly learning its vastness.
What I thought would be easy doesn't seem so easy to my brain. Here's my checkbox XAML:
<DataGridTemplateColumn Width="SizeToHeader" Header="FAI">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<CheckBox IsChecked="{Binding Path=fai}" Checked="FAI_CheckBox_Checked" Unchecked="FAI_CheckBox_Unchecked" />
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
And after ticking this I want to check another checkbox, which is currently:
<DataGridCheckBoxColumn Binding="{Binding Path=user_fai}" Width="Auto" Header="User FAI" Visibility="Visible" IsReadOnly="True"/>
So, for the first checkbox, I have my events created, but no idea now how to proceed, even after much searching the internet for an answer. Is this the correct route? Can it all be done in XAML?
|
|
|
|
|
If you always want the two checkboxes to have the same state, why not bind them to the same member?
<CheckBox IsChecked="{Binding Path=fai}" />
<CheckBox IsChecked="{Binding Path=fai, Mode=OneWay}" IsReadOnly="True" Width="Auto" Header="User FAI" Visibility="Visible" />
Otherwise, use the view model:
public bool fai
{
get { return _fai; }
set
{
_fai = value;
OnPropertyChanged();
if (value) user_fai = true;
}
}
Model-View-ViewModel (MVVM) Explained[^]
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Thanks for your help Richard. I have indeed decided to go down the MVVM path, so thank you for the pointer.
|
|
|
|
|
I have my WPF main project, and have a second project called Controls. Controls is referenced i the main project.
In controls I have a UserControl called HyperlinkView:
<TextBlock>
<pre>
<Hyperlink Command="{Binding LinkClickCommand}"
Click="Hyperlink_Click">
<TextBlock Text="{Binding LinkText}"/>
</Hyperlink>
There are 2 DP's in the code behind for the LinkText and LinkClickCommand, as well as the event handdler for the Click.
Now in my Main project I an dynamically added these HyperlinkView controls at run time.
The question is this... How do I apply a style to this control from within the Main project? For this control I may want the font size to be 24 and the foreground to be Teal. How do I apply styling to both the hyperlink and the textbox from within my Main project?
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
The easiest way would be to create a named style and apply that. This would be applied to the TextBlock inside your HyperLink.
This space for rent
|
|
|
|
|
So give both the Link and textblock names, then create a named style for them in my Main project?
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
But in the style, how do you specified which element in the control the style items are applied to?
How do you apply a stlye to each of the elements in the control from with in the style?
<Style x:Key="HyperlinkViewStyle"
TargetType="{x:Type myControls:HyperlinkView}">
How do do style the TextBlock or the Hyperlink in here?
</Style>
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
modified 2-Feb-17 13:57pm.
|
|
|
|
|
I realize that this is not a Telerik forum but I also poured through their forums to no avail. Long story short, I am using NHibernate to hydrate my viewmodels and exposing complex objects with their related objects to my view. The issue is that in my grid I have a combobox column that has a collection of objects from the viewmodel, the selectedvalue of which will update the object of the selected item. When I change the combobox everything is great, everything is talking back and forth, all is well. But when I close the control and reopen it, it does not select any value for the column.
All code is cut for brevity:
View:
<telerik:GridViewComboBoxColumn x:Name="Client"
ItemsSource="{Binding Clients}"
DataMemberBinding="{Binding Client}"
DisplayMemberPath="Name"
SelectedValueMemberPath=""
Header="Client"
Width="125" />
ViewModel:
public ObservableCollection<Client> Clients { get; private set;}
Entity:
public class Claim : Entity<int>
{
public virtual Client Client { get; set; }
}
NHibernate Mapping
public ClaimMap()
{
Table("Claim");
LazyLoad();
Id(x => x.Id).GeneratedBy.Identity().Column("id");
References(x => x.Client).Column("clientId").Not.Nullable();
}
}
}
I am sure I could just expose the id values on the Claim object and wire it up that way but it really is swimming against the current of NHibernate to do so.
Thoughts?
Cheers, --EA
|
|
|
|
|
My guess would be that you're not using TwoWay binding.
|
|
|
|
|
Trying to show enum descriptions in a DataGrid DataGridComboBoxColumn . here's my XAML so far:
<Window.Resources>
<wpfconv:EnumDescriptionConverter x:Key="EnumDescriptionConverter" />
<ObjectDataProvider MethodName="GetValues"
ObjectType="{x:Type sys:Enum}"
x:Key="accessEnums">
<ObjectDataProvider.MethodParameters>
<x:Type TypeName="enums:AccessLevel" />
</ObjectDataProvider.MethodParameters>
</ObjectDataProvider>
</Window.Resources>
and
<DataGridComboBoxColumn Header="Access"
ItemsSource="{Binding Source={StaticResource accessEnums}, Mode=OneWay}"
SelectedItemBinding="{Binding Access}"
Width="100">
</DataGridComboBoxColumn>
and the enum:
public enum AccessLevel
{
[Description("No Acccess")]
NoAccess = 0,
[Description("Full Acccess")]
HasAccess = 1
}
When I run it I see the enum value in the combo, not the descriptions. Can someone show me how to do this?
Thanks
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
That is clear, because you are not telling the WPF to actually write the Description to the rendering; as I believe, it is just trying to call a simple ToString and then writing what is found there.
For this thread, it is pretty much clear that what you need to do is you need to create a converter for your binding and then read the DescriptionAttribute of the current enum value. Then render that Description in the returning object. You might need to implement the converter, and then add that as an object.
The sh*t I complain about
It's like there ain't a cloud in the sky and it's raining out - Eminem
~! Firewall !~
|
|
|
|
|
I'm trying to extend the WPF dataGrid so I can bind to SelectedItems when SelectionMode = Extended.
First I have this
public class DataGridEx : DataGrid
{
public DataGridEx()
{
this.SelectionChanged += CustomDataGrid_SelectionChanged;
}
public IList SelectedItemsList
{
get { return (IList)GetValue(SelectedItemsListProperty); }
set { SetValue(SelectedItemsListProperty, value); }
}
public static readonly DependencyProperty SelectedItemsListProperty =
DependencyProperty.Register("SelectedItemsList", typeof(IList), typeof(DataGridEx), new PropertyMetadata(null));
private void CustomDataGrid_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
this.SelectedItemsList = this.SelectedItems;
}
}
Then my XAML
<ctrls:DataGridEx x:Name="_ScenariosTable"
Grid.Column="1"
Grid.Row="6"
SelectionMode="Extended"
ItemsSource="{Binding Scenarios}"
SelectedItemsList="{Binding SelectedScenarios, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}">
and finally my View Model
private List<Scenario> _SelectedScenarios;
public List<Scenario> SelectedScenarios
{
get { return _SelectedScenarios; }
set
{
if (_SelectedScenarios != value)
{
_SelectedScenarios = value;
RaisePropertyChanged("SelectedScenarios");
}
}
}
The binding works because the SETTER is called, yet 'value' is always null.
What's wrong here?
Thanks
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
According to the comments on this StackOverflow answer[^], it should work if you use IList instead of IList<T> in your viewmodel.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
That did it! Thanks!
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
I have this combo box:
<ComboBox Grid.Row="1"
Grid.Column="0"
ItemsSource="{Binding Categories}"
SelectedItem="{Binding SelectedRight.Category}"
IsEnabled="{Binding RightsFieldsEnabled}"
Width="250"
Margin="2"
Style="{StaticResource comboBoxStyle}">
<ComboBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Category}"
FontSize="14"/>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
When a Category is selected is saves it correctly to the Category property of the Right entity. However, when the data is reloaded the correct Category is not selected in the combo.
What am I doing wrong here?
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
Chances are that your objects and lists are (some sort of) based on the instance properties or fields of the object that is bound. Did you try any static fields here (try making the data source static and then see if that has any effect on reload)?
The sh*t I complain about
It's like there ain't a cloud in the sky and it's raining out - Eminem
~! Firewall !~
|
|
|
|
|
SelectedItem,mode="twoway"
Never underestimate the power of human stupidity
RAH
|
|
|
|