datacontext

PropertyChanged event null after setting DataContext

会有一股神秘感。 提交于 2019-12-14 03:11:05
问题 I am setting the DataContext for my View in the View's Constructor to an instance of my ViewModel, just standard stuff. Shortly thereafter, an UPDATE_RECENT_DOCUMENTS_LIST Event fires from the Event Aggregator which my ViewModel catches correctly. A property is changed and the onPropertyChanged method is called, but it fails as the PropertyChanged event is null. The very next thing I do is an action to the UI which raises a CREATE_PROJECT Event and the same ViewModel is receiving events,

Why does this.datacontext (Window) show data from viewModel and FrameContent.datacontext (page) does not?

我与影子孤独终老i 提交于 2019-12-13 22:13:37
问题 Why does this.datacontext (Window) show data from viewModel and FrameContent.datacontext (page) does not? Currently, I load the data from a page's view to the window. Instead of loading it directly to the dataContext of the window, I want to load it in the dataContext of the frame where the data is showed. Below my code: ViewConfiguration.xaml: <Frame x:Name="FrameContent" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch" NavigationUIVisibility="Hidden" BorderThickness=

DataContext binding

女生的网名这么多〃 提交于 2019-12-13 19:22:28
问题 What I have is three different views. I have view models for each of these views. What I do is set the datacontext of the view to a new instance of the respective view model and this works like shown below: public LoginScreen() { InitializeComponent(); DataContext = new LoginScreenViewModel(); } This works as desired. Everything binds correctly and such. Now, I have each of my views set up as UserControls. I have my Window that has datatemplates for each of my views as shown below: <Window

How to define DataContext in XAML using StaticResource

天大地大妈咪最大 提交于 2019-12-13 13:03:43
问题 I want to declare a DataContext through a static resource in XAML as a binding for the Customers in the Northwind database. I can do this easily in code (C#) but want to learn how to do in XAML. I have tried all of the examples I can find but none of them work for me. I believe the issue is in the two XAML lines of code I have labeled [Option1] and [Option2]. Can you clarify what the syntax for this really should be? C# namespace DataGridEF { public partial class MainWindow : Window { public

How to bind an element to a property which belongs to the root element of a control?

五迷三道 提交于 2019-12-13 02:36:09
问题 The question may sound a little confusing, but the problem I'm currently facing is this: <Button x:Class="sandbox.BtnLabel" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" x:Name="this"> <Button.ToolTip> <TextBlock Background="Yellow" Text="{Binding ElementName=this, Path=LabelText}"/> <

DataContext in UserControls

梦想与她 提交于 2019-12-13 02:26:23
问题 How are DataContext in UserControls usually set? If I do something like the below in my UserControl, DataContext = this In my Window or other Controls when I want to use the Control with a Binding, I will have to have a RelativeSource to point to the Window/UserControl <local:UserControl1 TextContent="{Binding Text1, RelativeSource={RelativeSource AncestorType={x:Type Window}}}" /> Is the way to bind Controls within UserControls: set use RelativeSource in UserControls instead of DataContext ?

WPF ProgressBar Not Updating with INotifyPropertyChanged

帅比萌擦擦* 提交于 2019-12-13 00:42:57
问题 I have a UserControl with several TextBox controls and a ProgressBar. The TextBox controls properly reflect the properties in codebehind to which they are bound. The ProgressBar does not respond to property change, however. My XAML: <UserControl xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008

DataContext of DataTemplate in ToolTip Style in WPF

▼魔方 西西 提交于 2019-12-12 18:19:41
问题 I can't seem to find the right DataContext for the Grid in the ToolTipStyle Style. Just a blank ToolTip appears. <Window.Resources> <DataTemplate x:Key="ListTemplate"> <StackPanel> <Grid> <TextBlock Text="{Binding Path=Name}"> <TextBlock.ToolTip> <ToolTip Style="{StaticResource ToolTipStyle}" /> </TextBlock.ToolTip> </TextBlock> </Grid> </StackPanel> </DataTemplate> <Style TargetType="ToolTip" x:Key="ToolTipStyle"> <Setter Property="ContentTemplate"> <Setter.Value> <DataTemplate> <Grid>

Binding to a Datacontext of an ancestor

我是研究僧i 提交于 2019-12-12 12:41:13
问题 It would be best if showed you my code first and then ask the question: <Window DataContext="{Binding RelativeSource={RelativeSource Self}}"> <Grid> <DataGrid ItemsSource="{Binding Printers}" > <DataGrid.Columns> <DataGridComboBoxColumn Header="Drucker Typ" ItemsSource="{Binding Relative" SelectedItemBinding="{Binding PrinterType, Mode=TwoWay}" Width="Auto" ItemsSource="{Binding}" /> </DataGrid.Columns> </DataGrid> </Window> I have the DataGridComboBoxColumn and want to bind the ItemsSource

Linq and DataContext

无人久伴 提交于 2019-12-12 09:18:28
问题 Would it be ok to have only one DataContext per app and share that through an singleton? I ask this because i would like to have the DataContext in every form but i realized that, if i change some enity in one DataContext, i have ro refresh it, if used before. eg form1: db = GetContext() item=(from p in db.Table where p.id=1 select p) on another form db = GetContext() item=(from p in db.Table where p.id=1 select p) item.value="test" back on the original form i have to do db.Refresh