小编Ray*_*nan的帖子

如何在属性更新后调用方法

我有一个绑定到 viewmodel.SelectedDate 的 DatePicker 控件。我没有使用 propfull,而是使用 CTK [ObservableProperty]。当我选择一个新日期时,我想调用另一个函数,该函数根据该新日期获取新的数据集。还有其他注释吗?

    /// Set by the Date Control on the form
    [ObservableProperty]
    //[AlsoCallThisFunction(DisplayBookings)]
    public DateTime bookingDate;

    ///I want to call this for a fresh dataset
    ///after the bookingDate is set
    void DisplayBookings()
    {
        GoToDatabaseAndGetNewRecordset(bookingDate);
    }
Run Code Online (Sandbox Code Playgroud)

旧的做法:

    //private DateTime bookingDate;

    //public DateTime BookingDate
    //{
    //    get { return bookingDate; }
    //    set { 
    //        bookingDate = value;
    //        DisplayBookings();

    //    }
    //}
Run Code Online (Sandbox Code Playgroud)

c# mvvm windows-community-toolkit

7
推荐指数
1
解决办法
2667
查看次数

实体框架我的AddOrUpdate函数在哪里?

我正在使用Entity Framework 6.1.3对抗SQL Server 2012数据库的VS2015 WCF服务

我从"现有数据库中的Code First"开始,然后从CF进行所有编辑.

我有基本的读写操作.我可以.添加到一个表格很好,它按预期工作,但我不能.AddOrUpdate,因为我看到人们在谈论因为它不是在intellisense下拉列表中我输入!?

这是一个屏幕抓取......

没有.AddOrUpdate

c# entity-framework

5
推荐指数
1
解决办法
3724
查看次数

从 ObservableCollection 添加或删除项目时列表框不更新

我有一个“Hello World”类型的应用程序。
列表框.ItemsSource = 玩家。Players 是实现 INotifyPropertyChanged 的​​ Player 的 ObservableCollection。

当我在 Players 构造函数中添加项目时,项目显示正常。当我更新现有项目时,更改会得到反映。但是,当我添加或删除 ObserveableCollection 的项目时,列表框不会反映添加/删除的项目。

主页中的 xaml:

    <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
        <ListBox Name="lstPlayers" ItemsSource="{Binding}" Margin="12,66,13,24" Grid.Row="1">
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <!--<StackPanel Background="#FFD1D1D1">-->
                    <Grid Margin="0,0,0,0" Grid.RowSpan="2">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="60"/>
                            <ColumnDefinition Width="*"/>
                        </Grid.ColumnDefinitions>
                        <TextBlock Grid.Column="0" Text="{Binding Number}" FontSize="48"  />
                        <TextBlock Grid.Column="1" Text="{Binding Name}" FontSize="48" />
                    </Grid>
                    <!--</StackPanel>-->
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>
        <Button Content="Button" Height="95" HorizontalAlignment="Left" Margin="183,350,0,0" Name="button1" VerticalAlignment="Top" Width="260" Click="button1_Click" />
        <Button Content="Button" Height="72" HorizontalAlignment="Left" Margin="198,472,0,0" Name="button3" VerticalAlignment="Top" Width="232" Click="button3_Click" />
    </Grid>
Run Code Online (Sandbox Code Playgroud)

列表框绑定在后面的代码中:

  lstPlayers.ItemsSource …
Run Code Online (Sandbox Code Playgroud)

wpf listbox itemssource windows-phone-7

3
推荐指数
1
解决办法
7906
查看次数

仅在编译时在 DataContext 中找不到 Xamarin VS2022 成员

(请注意,我正在注释掉从 开始的所有内容<!--<ListView.ItemTemplate>

如果我取出注释块并尝试运行代码,我会收到编译器错误“

在 DataContext XFC0045 绑定中找不到成员:在“ViewModels.FlightViewModel”上找不到属性“SyllabusNumber”

注意:不仅仅是 SyllabusNumber,任何字段都会失败,但它只会捕获第一个字段。

如果我使用注释掉的代码运行它,应用程序将启动并向我显示 object.tostring() 文本项“models.LessonModel”的列表。当应用程序运行时,我取消注释代码并使用热重载,一切正常。

窗口的 DataContext 设置为 ViewModel,Lessons 是 VM 中的公共 ObservableCollection。与虚拟机的所有其他绑定都工作正常且符合预期。我已将所有访问修饰符设置为“public”。我已经在VS2022和VS2022 Preview中尝试过了。

                    <ListView  x:Name="listView" ItemsSource="{Binding Lessons}" Margin="30" >
                        <!--<ListView.ItemTemplate>
                            <DataTemplate>
                                <ViewCell>
                                    <StackLayout BackgroundColor="#eee" Orientation="Horizontal">
                                        --><!-- <Image Source="{Binding image}" />  --><!--

                                        <StackLayout Orientation="Vertical">
                                            
                                            <StackLayout Orientation="Horizontal">
                                                <Label Text="{Binding SyllabusNumber}" TextColor="#ddd" BackgroundColor="#333" Padding="5,0,5,0"/>
                                                <Label Text="{Binding Name}" TextColor="#333" />
                                            </StackLayout>
                                            
                                            
                                            <Label Text="{Binding Description}" TextColor="#666" />
                                            
                                        </StackLayout>
                                    </StackLayout>
                                </ViewCell>
                            </DataTemplate>
                        </ListView.ItemTemplate>-->
                    </ListView>
Run Code Online (Sandbox Code Playgroud)

c# xaml xamarin visual-studio-2022

2
推荐指数
1
解决办法
1958
查看次数