|
Is that a joke?
You can use whatever you want.
I only tried to provide another possible solution.
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
It seems like everybody has neglected to give you the *RIGHT* answer and just continued to support your wrong direction. You should only have a single template and use triggers, VisualStateManager, DependencyProperties, etc. to modify your data template.
The only time having multiple templates is appropriate is if you are making a control that needs to look different in different situations like one look for Aero and one look for classic, etc.
Doesn't seem like your situation applies in this case, so I'd stick to the single template.
|
|
|
|
|
Actually, I've tried the code with setting list view's ItemTemplate instead of setting columns's CellTemplate what I needed.
Therefore, I applied the the method with 2 data templates in list view's resource:
<DataTemplate x:Key="Column3_ShowStandColumn">
<Border BorderThickness="0,0,1,0" BorderBrush="Gray" Margin="-6,0,-6,0">
<TextBlock Margin="2,1,1,1" Text="{Binding Path=stand_name}"></TextBlock>
</Border>
</DataTemplate>
<DataTemplate x:Key="Column3_HideStandColumn">
<Border BorderThickness="0,0,0,0" BorderBrush="Gray" Margin="-6,0,-6,0">
<TextBlock Margin="2,1,1,1" Text="{Binding Path=stand_name}"></TextBlock>
</Border>
</DataTemplate>
And this code in combo box's SelectionChanged event:
if (selectedStand.stand_name != "Все")
{
...
DataTemplate dt = lstvTCKeyValue.FindResource("Column3_HideStandColumn") as DataTemplate;
gv.Columns[2].CellTemplate = dt;
...
}
else
{
...
DataTemplate dt = lstvTCKeyValue.FindResource("Column3_ShowStandColumn") as DataTemplate;
gv.Columns[2].CellTemplate = dt;
...
}
Thank you all for suggestions and help.
|
|
|
|
|
Indeed, and for those who are interested, here's an example of a template that can be applied to a checkbox. Basically, this DataTemplate uses a trigger to change a control template when the IsSelected value changes. Just for clarity - this isn't the best way to restyle a checkbox, it just demonstrates using a DataTemplate and ControlTemplate elements. BTW - this is a purely XAML based alternative to a DataTemplateSelector.
<ControlTemplate x:Key="OnTemplate">
<Grid ToolTip="{Binding Tag, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type CheckBox}}}">
<Rectangle HorizontalAlignment="Left" Margin="0" VerticalAlignment="Center" Width="80" Height="20" RadiusX="3" RadiusY="3">
<Rectangle.Fill>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="#FF6183DC" Offset="0"/>
<GradientStop Color="#FFC6CDE0" Offset="1"/>
</LinearGradientBrush>
</Rectangle.Fill>
</Rectangle>
<TextBlock HorizontalAlignment="Left" VerticalAlignment="Center" Text="ON" TextWrapping="Wrap" Margin="8,0,0,0" FontSize="16" FontWeight="Bold" Foreground="#FFFEFCFC"/>
<Rectangle RadiusX="3" RadiusY="3" HorizontalAlignment="Left" Margin="40,0,0,0" VerticalAlignment="Center" Width="40" Height="20">
<Rectangle.Fill>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="#FFB5B1B1" Offset="0.004"/>
<GradientStop Color="White" Offset="1"/>
</LinearGradientBrush>
</Rectangle.Fill>
</Rectangle>
</Grid>
</ControlTemplate>
<ControlTemplate x:Key="OffTemplate">
<Grid ToolTip="{Binding Tag, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type CheckBox}}}">
<Rectangle HorizontalAlignment="Left" Margin="0" VerticalAlignment="Center" Width="80" Height="20" RadiusX="3" RadiusY="3">
<Rectangle.Fill>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="#FFE0E7F8" Offset="0"/>
<GradientStop Color="#FFF2F4FA" Offset="1"/>
</LinearGradientBrush>
</Rectangle.Fill>
</Rectangle>
<TextBlock HorizontalAlignment="Left" VerticalAlignment="Center" Text="OFF" TextWrapping="Wrap" Margin="44,0,0,0" FontSize="16" FontWeight="Bold" Foreground="#FFB3ABAB"/>
<Rectangle RadiusX="3" RadiusY="3" HorizontalAlignment="Left" Margin="1,0,0,0" VerticalAlignment="Center" Width="40" Height="20">
<Rectangle.Fill>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="#FFB5B1B1" Offset="0.004"/>
<GradientStop Color="White" Offset="1"/>
</LinearGradientBrush>
</Rectangle.Fill>
</Rectangle>
</Grid>
</ControlTemplate>
<DataTemplate x:Key="toggleTemplate">
<Control x:Name="toggleControl" Template="{StaticResource OnTemplate}" />
<DataTemplate.Triggers>
<DataTrigger Binding="{Binding IsChecked, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type CheckBox}}}" Value="False">
<Setter Property="Template" TargetName="toggleControl" Value="{StaticResource OffTemplate}" />
</DataTrigger>
</DataTemplate.Triggers>
</DataTemplate>
|
|
|
|
|
Hello again!
It is another time I encounter this error: "objects added to an IDictionary must have a Key attribute or some other type of key associated with them.". I searched google to find out what is going on, but in every case the reason was that somebdy didn't set either Key or TargetType.
I my case, I set the TargetType, but it doesn't work. In my previous post the problem was that I was using a UserControl. Now I try to set a template of a ToggleButton which is not a UserControl. WTH is going on?
<ControlTemplate TargetType="ToggleButton">
<ControlTemplate.Triggers>
<DataTrigger Binding="{TemplateBinding IsChecked}" Value="True">
<Setter Property="Opacity" Value="1" />
</DataTrigger>
<DataTrigger Binding="{TemplateBinding IsMouseOver}" Value="True">
<Setter Property="Opacity" Value="0.7" />
</DataTrigger>
</ControlTemplate.Triggers>
</ControlTemplate>
(...)
<ToggleButton Grid.Row="3" Grid.Column="1" HorizontalAlignment="Center" VerticalAlignment="Center" Background="Transparent" BorderThickness="0" BorderBrush="Transparent" Opacity="0.3">
<Image Source="{StaticResource CheckedImage}" Height="16" />
</ToggleButton>
The error started to appear since I changed something. I had tried to revert my recent changes but I couln't work out what is wrong
EDIT: I've tried to set x:Key and reference Template={StRes key} and got exception:
{"'Set property 'System.Windows.DataTrigger.Binding' threw an exception.' Line number '59' and line position '18'."}
Inner:
{"Unable to cast object of type 'System.Windows.TemplateBindingExpression' to type 'System.Windows.Data.BindingBase'."} Inner:null
Edit2: IsChecked IS a dep property
Any ideas?
Greetings - Jacek
modified on Monday, May 16, 2011 5:46 AM
|
|
|
|
|
This works:
<Style TargetType="ToggleButton">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ToggleButton">
<Image MouseDown="Image_MouseDown" Source="{StaticResource CheckedImage}" Height="16" />
</ControlTemplate>
</Setter.Value>
</Setter>
<Style.Triggers>
<DataTrigger Binding="{Binding Path=IsChecked, RelativeSource={RelativeSource Mode=TemplatedParent}}" Value="True">
<Setter Property="Opacity" Value="1" />
</DataTrigger>
<DataTrigger Binding="{Binding Path=IsMoueseOver, RelativeSource={RelativeSource Mode=TemplatedParent}}" Value="True">
<Setter Property="Opacity" Value="0.7" />
</DataTrigger>
</Style.Triggers>
</Style>
private void Image_MouseDown(object sender, MouseButtonEventArgs e)
{
var img = (Image)sender;
var toggle = (ToggleButton)img.TemplatedParent;
toggle.IsChecked = true;
}
BUT the triggers doesn't work. I mouseover and opacity doesn't change. I click opacity doesn't change
Oh WPF makes me head not working. I is confusing.
Greetings - Jacek
|
|
|
|
|
When you write ControlTemplate you can use normal Triggers and EventTriggers . DataTriggers are meant to use along with DataTemplate .
And also Key is a must for <ControlTemplete> whereas Style doesn't require one.
|
|
|
|
|
Yes, that's true. This worked for me:
<ControlTemplate.Triggers>
<Trigger Property="IsChecked" Value="True">
<Setter Property="Opacity" Value="1" />
</Trigger>
</ControlTemplate.Triggers>
You may need to supply TargetName for the Setter.
|
|
|
|
|
TargetName is not required in his case.
|
|
|
|
|
Whoa! Thanks.
Greetings - Jacek
|
|
|
|
|
Good Day All
I am intergrating a Credit card Payment from a third party gateway. They dont expose web methods, so we have to use their page to process the CC. So i used a Telerik HtmlContainer to host their page and now i want to do a post and get a response URL that will contain the results that will tell me if the payment went through.
https://www.vcs.co.za/vvonline/ccpay.asp?p1=FP99&p3=Test%20ccPay
i have attached the documentation
http://www.vbforums.com/attachment.php?attachmentid=83913&d=1305463574[^]
MOre info https://www.vcs.co.za/
Have anyone does this before ?
Thanks
Vuyiswa Maseko,
Spoted in Daniweb-- Sorry to rant. I hate websites. They are just wierd. They don't behave like normal code.
C#/VB.NET/ASP.NET/SQL7/2000/2005/2008
http://www.vuyiswamaseko.com
vuyiswa@its.co.za
http://www.itsabacus.co.za/itsabacus/
modified on Sunday, May 15, 2011 8:47 AM
|
|
|
|
|
This is almost certainly a question for the provider. I would say that you probably want to find a provider that supports making payments through a web service because Silverlight is good at calling those and you can use your own UI. But what I would expect is that this merchant will let you set a 'success URL' which is a page on your server that gets called when a transaction is completed, with a unique token for the transaction along with some other stuff. That can set your own database entry and the Silverlight can poll for status updates. I can only help in the most general of terms though since I've never used that provider.
|
|
|
|
|
Hello,
I want to apply a control template to all instances of my user control. I try to set TargetType of a ControlType but it doesn't work. Setting a template by key works as expected.
<Canvas Name="DesignSurface" Grid.Row="1" Background="White"
MouseMove="DesignSurface_MouseMove" MouseDown="DesignSurface_MouseDown">
<Canvas.Resources>
<ControlTemplate x:Key="NetVisualTemplate" TargetType="{x:Type local:TransitionVisual}">
<Grid DataContext="{Binding RelativeSource={RelativeSource TemplatedParent}}">
<local:MoveThumb Template="{StaticResource MoveThumbTemplate}" Cursor="SizeAll"/>
<ContentPresenter Content="{TemplateBinding UserControl.Content}" IsHitTestVisible="False" />
</Grid>
</ControlTemplate>
</Canvas.Resources>
<local:TransitionVisual Canvas.Left="207" Canvas.Top="46" />
</Canvas>
How can I fix it? Thanks.
Greetings - Jacek
|
|
|
|
|
Don't specify x:Key and it will get applied to all instances. Of course in this case, it will only get applied to all instances on that canvas. If you want to globally apply it to all instances everywhere, you need to put it in a resource dictionary (without a key).
|
|
|
|
|
Thanks for answering!
I had found this tip on some forum and tried it but I get a compile-time error
All objects added to an IDictionary must have a Key attribute or some other type of key associated with them.
Greetings - Jacek
|
|
|
|
|
I have made a dirty work-around, revealing another error: The controls I wish to template derive from DesignerItem class (which is a UserControl). I wanted to template all of them by setting TargetType to that base type. Nope. Setting to "Control" also didn't work. So here it is:
<Style x:Key="DesignerItemStyle" TargetType="local:DesignerItem">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="local:DesignerItem">
<Grid DataContext="{Binding RelativeSource={RelativeSource TemplatedParent}}">
<local:MoveThumb Template="{StaticResource MoveThumbTemplate}" Cursor="SizeAll"/>
<ContentPresenter Content="{TemplateBinding UserControl.Content}" IsHitTestVisible="False" />
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style TargetType="local:TransitionVisual" BasedOn="{StaticResource DesignerItemStyle}" />
<Style TargetType="local:PlaceVisual" BasedOn="{StaticResource DesignerItemStyle}" />
Still, I do not consider the problem as solved
Greetings - Jacek
|
|
|
|
|
You can't template UserControls. You'd need a custom control for that...
See COntrol Authoring Overview[^]
Mark Salsbery
Microsoft MVP - Visual C++
modified on Saturday, May 14, 2011 7:36 PM
|
|
|
|
|
Thanks for answering an providing a great resource. This will probably explain many issues. Just not at the moment, you know [2:30 AM]. Cheers!
Greetings - Jacek
|
|
|
|
|
Good Day All
I have a strange situation here. When a user logs in i store the username or userid in the Cookie. So i have a generic method that retrieves that value and when i debug this, i can see that the value is retrieved nicely and i assign that value to a property like this
ContactsModel model = new ContactsModel();
model.iUserid = Convert.ToInt32(GenericMethods.GenericMethods.GetCookie("UserID"));
and after that Asynchronously i call the Business Layer WCF Service
like this
business.AddContactNumberAsync(model);
business.AddContactNumberCompleted += new EventHandler<AddContactNumberCompletedEventArgs>(business_AddContactNumberCompleted);
and the Completed Event like this
void business_AddContactNumberCompleted(object sender, AddContactNumberCompletedEventArgs e)
{
if (e.Error == null)
{
if (e.Result.ToString() == "")
{
lblError.Visibility = System.Windows.Visibility.Visible;
lblError.Content = "Successfully Added";
lblError.Background = new SolidColorBrush(Colors.Green);
this.DialogResult = true;
}
else
{
lblError.Visibility = System.Windows.Visibility.Visible;
lblError.Content = e.Result;
lblError.Background = new SolidColorBrush(Colors.Red);
}
}
else
{
lblError.Visibility = System.Windows.Visibility.Visible;
lblError.Content = e.Result;
lblError.Background = new SolidColorBrush(Colors.Red);
}
}
and in my Business Layer Service , i wanted to make if the value is corrupted in the Silverlight side or Business Layer side and i receive a call like this in the Business layere Service
public string AddContactNumber(ContactsModel Model)
{
string Error = string.Empty;
eCashDataLayer.IeCashDatalayerClient Datalayer = new IeCashDatalayerClient();
if (Model.iUserid != 0)
{
Error = Datalayer.AddContactNumber(Model);
}
else
{
Error = "Invalid Userid";
}
return Error;
}
it always return "Invalid Userid" , i am not sure what is the problem because this has been working all along.
Thanks
Vuyiswa Maseko,
Spoted in Daniweb-- Sorry to rant. I hate websites. They are just wierd. They don't behave like normal code.
C#/VB.NET/ASP.NET/SQL7/2000/2005/2008
http://www.vuyiswamaseko.com
vuyiswa@its.co.za
http://www.itsabacus.co.za/itsabacus/
|
|
|
|
|
I'm not sure what's going on based on your post, but I may have missed something.
But can't you step through in the debugger and see where Model.iUserid becomes 0?
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
hi Mark
I tried , from Silverlight the value is passed to the service , i am just surprised why all of a sudden it does this.
Vuyiswa Maseko,
Spoted in Daniweb-- Sorry to rant. I hate websites. They are just wierd. They don't behave like normal code.
C#/VB.NET/ASP.NET/SQL7/2000/2005/2008
http://www.vuyiswamaseko.com
vuyiswa@its.co.za
http://www.itsabacus.co.za/itsabacus/
|
|
|
|
|
This[^] is how would be setting a cookie in Silverlight. I did not see any code which did this here.
The funniest thing about this particular signature is that by the time you realise it doesn't say anything it's too late to stop reading it.
|
|
|
|
|
Good Day Abhinav
this is the exact code i use. The Problem is not in storing and retrieving of the cookie, but it lies in transporting it from the Silverlight to a service.when i pass it to a service method, on the way the value get lost. This code was working for days, after i formated my machine the same thing does not work anymore.
This is my generic functions i use to deal with cookies and when i debug i can see the value be retrieved from a cookie and being passed to a wcf method.
public static void DeleteCookie(string key)
{
DateTime expiration = DateTime.UtcNow - TimeSpan.FromDays(1);
string cookie = String.Format("{0}=;expires={1}", key, expiration.ToString("R"));
HtmlPage.Document.SetProperty("cookie", cookie);
}
public static void SetCookie(string key, string value)
{
DateTime expiration = DateTime.UtcNow + TimeSpan.FromDays(2000);
string cookie = String.Format("{0}={1};expires={2}", key, value, expiration.ToString("R"));
HtmlPage.Document.SetProperty("cookie", cookie);
}
public static string GetCookie(string key)
{
string[] cookies = HtmlPage.Document.Cookies.Split(';');
key += '=';
foreach (string cookie in cookies)
{
string cookieStr = cookie.Trim();
if (cookieStr.StartsWith(key, StringComparison.OrdinalIgnoreCase))
{
string[] vals = cookieStr.Split('=');
if (vals.Length >= 2)
{
return vals[1];
}
return string.Empty;
}
}
return null;
}
Thanks
Vuyiswa Maseko,
Spoted in Daniweb-- Sorry to rant. I hate websites. They are just wierd. They don't behave like normal code.
C#/VB.NET/ASP.NET/SQL7/2000/2005/2008
http://www.vuyiswamaseko.com
vuyiswa@its.co.za
http://www.itsabacus.co.za/itsabacus/
|
|
|
|
|
Hi,
I read about MVVM model. Using MVVM model i can reduce the code behind.
What does it Mean?
As MVVM model is separating the view, Model and ViewModel.
What is the actual use of ViewModel.
can't I bind the data from model itself rather than ViewModel?
Thanks,
Umesh Tayade
|
|
|
|
|
I also just started programming with MVVM pattern and I had a good start looking at Karl Shifflet's MVVM training "In the Box".
Try it out, it should provide you with a brief overview to start with:
In the Box MVVM Training[^]
Kind regards,
Nico
|
|
|
|
|