8 Answers, 1 is accepted
0
Hello Michael,
We need some more info in order to advice you better. You could elaborate more on the structure of your ViewModels and their properties.Thank you in advance for your cooperation.
Kind regards,
Petar Mladenov
the Telerik team
We need some more info in order to advice you better. You could elaborate more on the structure of your ViewModels and their properties.Thank you in advance for your cooperation.
Kind regards,
Petar Mladenov
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0

Michael
Top achievements
Rank 1
answered on 10 Jun 2011, 08:15 AM
OK
in my view I currently have
then the viewmodel exposes a database Timespan as a string such as
I want to switch the mask between accepting only min/sec for 90% of the time but being able to switch to hh-mm-ss if required?
in my view I currently have
<
telerik:GridViewMaskedTextBoxColumn
DataMemberBinding
=
"{Binding rTime}"
Header
=
"Stop Watch Time"
IsVisible
=
"{Binding ElementName=tbStopWatch, Path=IsChecked}"
MaskType
=
"DateTime"
Mask
=
"hh-mm-ss"
/>
then the viewmodel exposes a database Timespan as a string such as
public string rTime
{
get
{
//timespan & format
TimeSpan watchTime = TimeSpan.Parse(_Result.rTime);
return string.Format("{0:hh\\:mm\\:ss}", watchTime);
}
set
{
try
{
DateTime dt = DateTime.Parse(value);
//check if within first hour (Date Time)
if (dt.Hour == 12 || dt.Hour == 0)
{
var time = string.Format("{0:mm:ss}", dt);
_Result.rTime = String.Concat("00:" + time);
}
else
{
_Result.rTime = string.Format("{0:hh:mm:ss}", dt);
}
}
catch (Exception)
{
}
}
}
I want to switch the mask between accepting only min/sec for 90% of the time but being able to switch to hh-mm-ss if required?
0
Hello Michael,
I can see that you are binding to a string property and using a GridViewMaskedColumn. You have set the MaskType to DateTime and using a date time mask. The RadMaskedTextBox used in that column would expect a DateTime object instead of a string. However, you would not be able to bind the Mask property of the GridViewMaskedTextBoxColumn, because it is not a dependency property.
What you can do is to use the Cell(Edit)Template of the column and create a template with a RadMaskedTextBox control and bind the Mask and the Value properties of the control.
Regards,
Alex Fidanov
the Telerik team
I can see that you are binding to a string property and using a GridViewMaskedColumn. You have set the MaskType to DateTime and using a date time mask. The RadMaskedTextBox used in that column would expect a DateTime object instead of a string. However, you would not be able to bind the Mask property of the GridViewMaskedTextBoxColumn, because it is not a dependency property.
What you can do is to use the Cell(Edit)Template of the column and create a template with a RadMaskedTextBox control and bind the Mask and the Value properties of the control.
<
DataTemplate
>
<
telerik:RadMaskedTextBox
Value
=
"{Binding Date, Mode=TwoWay}"
Mask
=
"{Binding Path=Mask}"
MaskType
=
"DateTime"
/>
</
DataTemplate
>
Regards,
Alex Fidanov
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0

Michael
Top achievements
Rank 1
answered on 15 Jun 2011, 02:34 AM
is there an example of how to use templating for the gridview?
0

Michael
Top achievements
Rank 1
answered on 15 Jun 2011, 03:05 AM
so i have this:
and now the viewmodel shows:
but when i edit theres no mask at all?
actually taht viewmodel is a level above what the rest of the grid is referencing...how do i reference the "outer Viewmodel?"
<
telerik:GridViewMaskedTextBoxColumn
DataMemberBinding
=
"{Binding rTime}"
Header
=
"Stop Watch Time"
IsVisible
=
"{Binding ElementName=tbStopWatch, Path=IsChecked}"
MaskType
=
"DateTime"
Mask
=
"hh-mm-ss"
>
<
telerik:GridViewMaskedTextBoxColumn.CellEditTemplate
>
<
DataTemplate
>
<
telerik:RadMaskedTextBox
Value
=
"{Binding rTime, Mode=TwoWay}"
Mask
=
"{Binding Path=HourMask}"
MaskType
=
"DateTime"
/>
</
DataTemplate
>
</
telerik:GridViewMaskedTextBoxColumn.CellEditTemplate
>
</
telerik:GridViewMaskedTextBoxColumn
>
and now the viewmodel shows:
public string HourMask
{
get
{
return _hourMask ? "hh-mm-ss" : "mm-ss";
}
}
but when i edit theres no mask at all?
actually taht viewmodel is a level above what the rest of the grid is referencing...how do i reference the "outer Viewmodel?"
0
Hi Michael,
You could bind the Mask to the outer ViewModel (which I suppose is the DataContext of the RadGridView) with RelativeSource binding (AncestorType = RadGridView). For example:
All the best,
Alex Fidanov
the Telerik team
You could bind the Mask to the outer ViewModel (which I suppose is the DataContext of the RadGridView) with RelativeSource binding (AncestorType = RadGridView). For example:
<
telerik:RadMaskedTextBox
Mask
=
"{Binding Path=DataContext.Mask, RelativeSource={RelativeSource AncestorType={x:Type telerik:RadGridView}}}"
Value
=
"{Binding MyProperty, Mode=TwoWay}"
MaskType
=
"Numeric"
/>
All the best,
Alex Fidanov
the Telerik team
Do you want to have your say when we set our development plans?
Do you want to know when a feature you care about is added or when a bug fixed?
Explore the
Telerik Public Issue Tracking
system and vote to affect the priority of the items
0

Michael
Top achievements
Rank 1
answered on 21 Jun 2011, 12:55 AM
My solution was to add the parent Viewmodel to the constructor of the results viewmodel. So my Viewmodel now has...
and in the parent
and so in the view:
however since making these changes the edit field has been behaving quite eratically. When entering a number pressing - which normally moves form entering minutes to seconds in the mm-ss mask now just returns to mm in the first instance THEN moves to seconds on the 2nd press and if i dont press it after that it will now let me enter a number to the minutes columns??
public string HourMask
{
get
{
return _parentViewModel.HourMask;
}
}
and in the parent
public string HourMask
{
get
{
return _hourMask ? "hh-mm-ss" : "mm-ss";
}
}
and so in the view:
<
telerik:GridViewMaskedTextBoxColumn
DataMemberBinding
=
"{Binding rTime}"
Header
=
"Stop Watch Time"
IsVisible
=
"{Binding ElementName=tbStopWatch, Path=IsChecked}"
MaskType
=
"DateTime"
Mask
=
"hh-mm-ss"
>
<
telerik:GridViewMaskedTextBoxColumn.CellEditTemplate
>
<
DataTemplate
>
<
telerik:RadMaskedTextBox
Value
=
"{Binding rTime, Mode=TwoWay}"
Mask
=
"{Binding Path=HourMask}"
MaskType
=
"DateTime"
/>
</
DataTemplate
>
</
telerik:GridViewMaskedTextBoxColumn.CellEditTemplate
>
</
telerik:GridViewMaskedTextBoxColumn
>
however since making these changes the edit field has been behaving quite eratically. When entering a number pressing - which normally moves form entering minutes to seconds in the mm-ss mask now just returns to mm in the first instance THEN moves to seconds on the 2nd press and if i dont press it after that it will now let me enter a number to the minutes columns??
0
Hello Michael,
Can you please send us a sample project illustrating the issue because I cannot reproduce it on our side. And I am not sure I understand entirely the ViewModel logic from the code snippets you provided. And the cause for the issue might lay there.
Thank you in advance for your cooperation.
All the best,
Tina Stancheva
the Telerik team
Can you please send us a sample project illustrating the issue because I cannot reproduce it on our side. And I am not sure I understand entirely the ViewModel logic from the code snippets you provided. And the cause for the issue might lay there.
Thank you in advance for your cooperation.
All the best,
Tina Stancheva
the Telerik team
Do you want to have your say when we set our development plans?
Do you want to know when a feature you care about is added or when a bug fixed?
Explore the
Telerik Public Issue Tracking
system and vote to affect the priority of the items