|
I'm using a data bound treeview. I have added a dot next to each treeviewitem:
<HierarchicalDataTemplate DataType="{x:Type local:RuleGroup}" ItemsSource="{Binding Path=Rules}">
<StackPanel Orientation="Horizontal">
<Image Source="/RulesEngineUI;component/Media/bluedot.png" Height="8" Width="8" Margin="0,0,3,0"/>
<TextBlock Margin="0,0,5,0" FontWeight="Bold" >Group:</TextBlock>
<TextBlock>
<Hyperlink Name="Link" Style="{StaticResource LinkStyle}" Click="Link_Click">
<TextBlock Text="{Binding Path=GroupName}"></TextBlock>
</Hyperlink>
</TextBlock>
</StackPanel>
</HierarchicalDataTemplate>
Now I want to be able to change that image at runtime in the code behind.
How do I get a reference to the image?
Everything makes sense in someone's mind
|
|
|
|
|
You don't. The correct (WPF) way to do this is to have the image as a bound item and update the bound version, and this will update the UI.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
Got an example of that?
Everything makes sense in someone's mind
|
|
|
|
|
Hi All,
I am currently facing problem with the usage of 2way binding in Wpf.
Here is my problem
I have 1 Model class and a view model class and a view to render data from view model.
I am using the ObjectDataProvider for databinding in View.
I have a method in view model which will give me the List of data (of type model).
Now I am showing this list in a ItemsControl in view with datatemplate applied.
Here is my ItemsControl:
<ItemsControl ItemsSource="{Binding Source={StaticResource ResourceKey=F1TeamsList}}" ItemTemplate="{StaticResource ResourceKey=F1TeamViewTemplate}"/>
I have 2 text box in datatemplate and I have specified twoway binding there.
<ObjectDataProvider x:Key="F1TeamsList" ObjectType="{x:Type f1teamvm:F1TeamViewModel}" MethodName="GetF1Teams"/>
<DataTemplate x:Key="F1TeamViewTemplate">
<StackPanel>
<TextBox x:Name="teamDriver1Box" Text="{Binding Path=TeamDriver1}"/>
<TextBox x:Name="teamDriver2Box" Text="{Binding Path=TeamDriver2}"/>
</StackPanel>
</DataTemplate>
Here F1TeamList - is the objectdataprovider which returns list and F1teamViewTemplate is datatemplate.
And GetF1Teams is the function which provides me list.
But this code is not working as expected. It fetches data properly but 2way binding is not working here
Any Idea??
Regards
|
|
|
|
|
How have you defined the TeamDriver1 and TeamDriver2 properties? Are they raising the PropetyChanged event (the class must implement INotifyPropertyChanged for this)?
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
Yes I have implemented the INotifyPropertyChanged interface in the Model class.. And the two properties are raising the PropertyChanged event.
|
|
|
|
|
Try putting Text="{Binding Path=TeamDriver1, Mode=Default, UpdateSourceTrigger="LostFocus"}" to check that the update is getting triggered.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
Hello Pete,
The update is getting triggered .. My one more question is suppose I include 2 instance of the same view in my main page, If i update the data in 1 view then the data should be updated in the second view automatically rite ?? Correct me if I am worng .. Because this is not happening when I tried this scenario.
EG: I include my views in main window like this,
<StackPanel>
<customView:F1TeamView/>
<customView:F1TeamView/>
</StackPanel>
Regards,
|
|
|
|
|
It will only update if both views point to the same instance of data.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
It is the same instance of the data .. I initialize the list in the constructor of the view model and return the same list to both the views .. and one more thing . If I make changes to the data in ui and display the members in messagebox .. it will still show me the old values ..
|
|
|
|
|
How can we have vista style window (i.e. with drop-shadow and rounded corner) in Windows XP?
If I add 'PresentationFramework.Aero', it changes look for controls and not for main window.
I've set WindowStyle>None, Background>null and AllowTransparency>True for the window. And then, added a rectangle with rounded corner and drop-shadow. It emulates style perfectly but causing serious performance threat.
Can you people suggest me better approach?
|
|
|
|
|
Nope
Face it, any time you are bypassing the native rendering engine the OS uses you are going to take a performance hit. I don't care what anyone says.
This is why Vista and 7 are 'NEW'. They were written with the intent to support this new look and feel so the OS internals, all the way down to the rendering engines, were optimised towards that purpose intentionally.
On older OSes if you turn off native rendering and do all your own window drawing in your code you are always going to incur a performance hit because you are essentially moving that code up a layer, or at very least adding cycles in the way to signal an alternate rendering routine.
|
|
|
|
|
I have a page defined in xaml, and I'm using a 3rd-party control. I've created a style that overrides the control's template, and I've added a couple of new "parts" to the template.
In the C# code, when I call control.FindName("MyNewPart") , it returns null . I tried calling control.ApplyTemplate() before calling FindName , but it returns false.
How do I get that part from the control?
I GAVE UP ==============================
Yeah, I spent a couple days on this problem and with nothing to show for it that could be even remotely viewed as "progress".
.45 ACP - because shooting twice is just silly ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001
modified on Thursday, May 20, 2010 11:19 AM
|
|
|
|
|
4 Finding a Control in the ControlTemplate
private void OnFindChildInTemplate(object sender, RoutedEventArgs e)
{
Button btn = sender as Button;
ControlTemplate template = btn.Template;
Border child = template.FindName("TheBorder", btn) as Border;
var btn1 = child.TemplatedParent;
}
From Link[^]
|
|
|
|
|
Nope - won't work because a ControlTemplate object does not expose a FindName method in Silverlight.
.45 ACP - because shooting twice is just silly ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001
|
|
|
|
|
Is there any tool available in the market to migrate an ASP.NET based application to Silverlight application?
Appreciate a quick reply.
|
|
|
|
|
Don't cross-post: you should only post your question in one forum.
me, me, me
"The dinosaurs became extinct because they didn't have a space program. And if we become extinct because we don't have a space program, it'll serve us right!"
Larry Niven
|
|
|
|
|
No.
You're going to have to rewrite the entire thing.
.45 ACP - because shooting twice is just silly ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001
|
|
|
|
|
AFAIK, nothing exists.
My signature "sucks" today
|
|
|
|
|
Hi Shubhabrata,
There's exist no such tool to convert ASP.NET application to a Silverlight application. ASP.NET applications & Silverlight applications are two different things and there is no relation between them. One is in .aspx and the other is in .xaml. The controls are all different for them. Thus, you can't use any tool to convert from one to another.
If you want to migrate from one to the other, you have to know each technology first and then you have to manually convert them. Once migrated to Silverlight, you will get more power over your application with the help of Rich UI and StoryBoards.
Don't forget to Click on [Vote] and [Good Answer] on the posts that helped you.
Regards - Kunal Chowdhury | Software Developer | Chennai | India | My Blog | My Tweets | Silverlight Tutorial
|
|
|
|
|
Hi experts,
Created one WPF custrol control library, added reference of WPF toolkit.
used only datagrid as a base class in customcontrol1.cs file and trying to use it in WPF application, although all property of datagrid is exposed but data is not getting binded at runtime.. Pls anyone help me to rectify the issue
Thanks in advance..
|
|
|
|
|
kartheesh wrote: property of datagrid is exposed but data is not getting binded at runtim
What are you doing to bind your collection to your datagrid at runtime?
My signature "sucks" today
|
|
|
|
|
Hi Abhinav,
I used itemsource as well as datacontext, same is working fine when i used datagrid directly(i.e without custom control datagrid). Also I face same issue with custom control combobox, I feel something need to be added on generic.xaml
- kartheesh
|
|
|
|
|
Could you please post the CustomControl1.cs code?
|
|
|
|
|
Hi Castle,
Please find the below code, just i have inherited datagrid as shown below.
Namespace of datagrid is (Microsoft.Windows.Controls)
Source Code:
------------
[DefaultProperty("Columns")]
[ContentProperty("Columns")]
public partial class CustomControl1 : DataGrid
{
static CustomControl1()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(CustomControl1), new FrameworkPropertyMetadata(typeof(CustomControl1)));
}
}
|
|
|
|