UserControl data binding regression in 2.0.0
See original GitHub issueDescription
Binding the DataContext of a UserControl using an ElementName binding worked in 0.9.9, does not work in 2.0.0
Repro steps
MainWindow.xaml
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:local="clr-namespace:ViewModels;assembly=FsEmptyWindowsApp1">
<StackPanel>
<TextBox Name="Foo"/>
<local:TestControl DataContext="{Binding ElementName=Foo, Path=Text}"/>
</StackPanel>
</Window>
TestControl.xaml
<UserControl xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<TextBox Text="{Binding .}"/>
</UserControl>
Expected behavior
Typing into the TextBox Foo results in the same text in the TestControl.
Actual behavior
TestControl is blank. Binding error in Debug Output is
System.Windows.Data Error: 4 : Cannot find source for binding with reference ‘ElementName=Foo’. BindingExpression:Path=Text; DataItem=null; target element is ‘TestControl’ (Name=‘’); target property is ‘DataContext’ (type ‘Object’)
Known workarounds
None.
Related information
- Windows 8.1
- FsXaml 2.0.0 via nuget
- .NET 4.5
Issue Analytics
- State:
- Created 7 years ago
- Reactions:2
- Comments:8 (5 by maintainers)
Top Results From Across the Web
Data binding to a UserControl in WPF
I have a UserControl that I want to participate in data binding. I've set up the dependency properties in the user control, but...
Read more >Create user controls that support simple data binding
This walkthrough creates a simple data-bindable control from a User Control. Add a User Control item to the SimpleControlWalkthrough project:.
Read more >Data Widgets
9320 - Regression: If DataGrid is bound to table containing 01Oct99 and NumberFormat for column is ddmmmyy, date displays incorrectly as 10Jan99. 9318...
Read more >Search Results - CVE
The mission of the CVE® Program is to identify, define, and catalog publicly disclosed cybersecurity vulnerabilities.
Read more >vegan: Community Ecology Package
A constrained ordination object from cca, rda or capscale. ... metaMDS uses monoMDS as its NMDS engine from vegan version 2.0-0, ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
This has now been solved in 2.1. @mbergin please try https://www.nuget.org/packages/FsXaml.Wpf/2.1.0
It should now work with the ElementName bindings (as well as your
x:Reference
workaround).@ReedCopsey I found that
System.Windows.Markup.IComponentConnector
plays an important role here (but I don’t know exactly how).By implementing our UI class with this interface and the binding will work.
Example (sorry, haven’t tried the new library yet):
(In case you might wonder, this I copied from C# WPF generated code 😄 )