|
Does your XAML look like this?
<TextBlock Text="{Binding ErrorStatus.Text}" />
|
|
|
|
|
|
I've just tried your sample and it works perfectly for me (OK, I cheated in doing a little bit of code behind to add the DataContext, but the principal is still valid). My code-behind looks like this:
private MyService status = new MyService();
public MainWindow()
{
InitializeComponent();
this.DataContext = status;
}
private void Button_Click(object sender, RoutedEventArgs e)
{
status.TestMethod();
} The XAML looks like this:
<Window
x:Class="ErrorStatusTest.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:vm="clr-namespace:ErrorStatusTest"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Width="525"
Height="350"
Title="MainWindow">
<Grid>
<TextBlock
HorizontalAlignment="Left"
Margin="116,93,0,0"
VerticalAlignment="Top"
Text="{Binding ServiceStatus.Text}"/>
<Button
Width="75"
HorizontalAlignment="Left"
VerticalAlignment="Top"
Click="Button_Click"
Content="Button"/>
</Grid>
</Window>
|
|
|
|
|
Ah right ok, so you are binding to the service properties directly. If you saw in my previous post I have a property in my viewmodel and have a property changed event handler for when a property in the service changes. I was then setting the viewmodel property here.
Is it completely acceptable to declare a public property in my viewmodel for the interface instance in my viewmodelbase and bind to this directly?
So my ViewModelBase has this:
protected IService MyService
{
get { return GetService<IService>(); }
}
And in my ViewModel I would do this and bind to it directly from the XAML?:
public IService Service{get{return MyService;}}
|
|
|
|
|
Right. Got it.
OK, you've got quite a complicated little setup going on here, but the problem lies in the fact that you ultimately aren't propagating the change notification back up the chain here. Basically, your property changed bit in your previous sample only sets the ErrorStatus if the objects are different (which they aren't going to be), so the change notification doesn't reach the XAML (effectively, you've swallowed the change notification).
If I were you, I would look at using a property observer instead - Josh Smith details how to do this here[^].
|
|
|
|
|
Thanks Pete, yes I thought it was probably something like that.
How about the alternative of a public property for the interface instance?
I'll also take a look at the link you posted.
|
|
|
|
|
UCLAdam wrote: How about the alternative of a public property for the interface instance?
You could do that (this, in effect, is what the flattened version I used did). I prefer the property observer though.
|
|
|
|
|
Yes pretty much.
I've had a look at the post, looks interesting. Would you be able to give me pointers to how this would work in my sample?
Obviously I have the PropertyObserver class now. In my viewmodel would I do something like:
PropertyObserver<IService> _observer = new PropertyObserver<IService>(MyService).RegisterHandler(w => w.ErrorStatus, w=> ErrorChanged(w.ErrorStatus));
private object ErrorChanged(ErrorStatus errorStatus)
{
throw new NotImplementedException();
}
|
|
|
|
|
That looks about right to me.
|
|
|
|
|
I seem to get this error:
Error 2 The call is ambiguous between the following methods or properties: PropertyObserver<IService>.RegisterHandler(System.Linq.Expressions.Expression<System.Func<IService,object>>, System.Action<IService>)' and PropertyObserver<IService>.RegisterHandler(System.Func<IService,object>, System.Action<IService>)
|
|
|
|
|
If you can put your project on DropBox, I'll download it tonight and have a look at it.
|
|
|
|
|
Ok figured it out. In my frantic attempts to get it working I must have generated a method stub in the PropertyObserver class. This is why I was getting the error.
Thanks for your help Pete.
|
|
|
|
|
No problem. I'm glad you've got it working.
|
|
|
|
|
after put the control in wpf with winform, winform control in wpf control to cover
What is the reason, should I do?
picture
|
|
|
|
|
I'm sorry, but I'm not clear what you're asking. I've looked at the picture and I can see that you have airspace issues there - is this what you are asking about? An airspace issue is where you try to overlay Winforms and WPF rendering or a web page and WPF rendering.
This is a known issue with WPF (and will be fixed in the next release of WPF) because you are trying to combine rendering stacks - the fix is not to use a Windows Forms control. Find a WPF one that does what you want and use that, or write one yourself - it's generally not that hard.
|
|
|
|
|
There is a workaround which can be used to avoid this issue
You need to wrap the WinformHost with UserControl of WPF.
Follow these steps
1. Create a user control in the WPF (lookless control)
2. Create a style for this control
3. In the template of the style add WinformHost with x:name
4. Now override the OnApplyTemplate() of this control
5. Provide the .Child property of the Winformhost, added in the control
template to the actual winform control that you want to display.
Wrapping the winform control in the WPF control will avoid overlapping the WPF controls.
This overlapping is due to difference in the mechanism for rendering control in WPF and Winforms.
Winforms: uses GDI+ for rendering
WPF: uses DirectX for rendering
Hope this will help you to solve your problem
Happy Coding
modified 30-May-12 0:49am.
|
|
|
|
|
HI All
I want to use DirectShow in silverlight to capture video from webcam . Can any one suggest me the solution .Share some url for reference
cheers
|
|
|
|
|
The original DirectShow framework cannot be used with Silverlight.
This version[^] might help you.
Warning: I have never used this nor have a clue how it works, so I'm not sure how / what the results would be.
|
|
|
|
|
Thanks for your support.
I know it!i want a sample code project plz
|
|
|
|
|
If you want sample code, use Google or Bing and search for some. That's what we would do.
|
|
|
|
|
hey guys
im using pointer in my silverlight application in unsafe mode.
i checked Requested elevated trust when runnig in browser,add registry key AllowElevatedTrustAppsInBrowser and
signing the xap file.but when i executing my application it crashe with exception :Operation could destabilize the runtime"
Please help me to solve it.
Cheers
|
|
|
|
|
I have 2 questions...
I created a HierarchicalDataTemplate which is bound to a NodeModel
[Serializable]
public class NodeModel : ViewModelBase
{
public Guid Id { get; set; }
public string Caption { get; set; }
public string Description { get; set; }
public bool IsActive { get; set; }
public ImageSource Image { get; set; }
public bool IsExpanded { get; set; }
public string FileName { get; set; }
public NodeType Type { get; set; }
public List<NodeModel> Children { get; set; }
}
the template:
<HierarchicalDataTemplate DataType="{x:Type models:NodeModel}"
ItemsSource="{Binding Path=Children}">
<StackPanel Orientation="Horizontal"
Margin="2">
<Image Source="{Binding Image}"
Height="16"
Width="16"
Margin="0,0,2,0" />
<TextBlock Margin="0,0,5,0">
<Hyperlink NavigateUri="{Binding Caption}"
Foreground="#0C2DAA"
Command="{Binding Path=DataContext.SelectedLinkCommand,
RelativeSource={RelativeSource FindAncestor,
AncestorType={ x:Type views:ProjectListView}}}">
<InlineUIContainer>
<TextBlock Text="{Binding Caption}" />
</InlineUIContainer>
<Hyperlink.Style>
<Style TargetType="Hyperlink">
<Style.Triggers>
<Trigger Property="IsMouseOver"
Value="False">
<Setter Property="TextDecorations"
Value="{x:Null}" />
</Trigger>
</Style.Triggers>
</Style>
</Hyperlink.Style>
</Hyperlink>
<TextBlock.ToolTip>
<ToolTip>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<TextBlock FontWeight="Bold"
Text="{Binding Path=Caption}"
Grid.Row="0"
Margin="0,0,0,3" />
<TextBlock FontStyle="Italic"
Grid.Row="1"
Text="{Binding Path=FileName}"
Visibility="{Binding FileName,
Converter={StaticResource StringToVisConverter}}" />
<TextBlock Text="{Binding Path=Description}"
Grid.Row="2"
Visibility="{Binding Description,
Converter={StaticResource StringToVisConverter}}" />
</Grid>
</ToolTip>
</TextBlock.ToolTip>
</TextBlock>
</StackPanel>
</HierarchicalDataTemplate>
Finally, the treeview this is used in:
<telerik:RadTreeView x:Name="tvwTreeData"
ItemsSource="{Binding Path=Folders}"
ItemContainerStyle="{StaticResource ItemContainerStyle}"
SelectedItem="{Binding Path=SelectedTreeItem, Mode=TwoWay}" />
Problem 1) When I click a hyperlink, the correct tree node is not always selected. In other words, to make it work right I have to click the node, then the hyperlink on that node. How can I adjust this so that clicking a link selects its node?
Problem 2) How can I adjust this template so that nodes of Type.Folder don't show the hyperlink?
Thanks
If it's not broken, fix it until it is
|
|
|
|
|
This can be achieved by using the style template and DataTriggers (will give you the sample code). Before that, I am not sure why you want to use the Hyperlinks inside the TreeNode. Could you please help me to understand its need.
This will help me to give you the answer!
Happy Coding
|
|
|
|
|
You should not disrespect the other people, Or you should not ask the questions if you don not want to get the answer...
Happy Coding
|
|
|
|
|
Amardeep Deshmukh wrote: You should not disrespect the other people
What? What the hell are you talking about?
Amardeep Deshmukh wrote: Or you should not ask the questions if you don not want to get the answer...
Where did this come from???
If it's not broken, fix it until it is
|
|
|
|