Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 我忘了!我还有一个问题,我编辑了我的帖子。你有办法解决这个问题吗?嘿,亚历克斯,谢谢你的建议,我从来没有想过,但我以后会记得的:)。感谢您的代码,我有一个问题:在LoadData()方法中,您将当前数据视图分配给AlleKunden。但是什么时候最好调用L_C#_Wpf_Mvvm_Data Binding - Fatal编程技术网

C# 我忘了!我还有一个问题,我编辑了我的帖子。你有办法解决这个问题吗?嘿,亚历克斯,谢谢你的建议,我从来没有想过,但我以后会记得的:)。感谢您的代码,我有一个问题:在LoadData()方法中,您将当前数据视图分配给AlleKunden。但是什么时候最好调用L

C# 我忘了!我还有一个问题,我编辑了我的帖子。你有办法解决这个问题吗?嘿,亚历克斯,谢谢你的建议,我从来没有想过,但我以后会记得的:)。感谢您的代码,我有一个问题:在LoadData()方法中,您将当前数据视图分配给AlleKunden。但是什么时候最好调用L,c#,wpf,mvvm,data-binding,C#,Wpf,Mvvm,Data Binding,我忘了!我还有一个问题,我编辑了我的帖子。你有办法解决这个问题吗?嘿,亚历克斯,谢谢你的建议,我从来没有想过,但我以后会记得的:)。感谢您的代码,我有一个问题:在LoadData()方法中,您将当前数据视图分配给AlleKunden。但是什么时候最好调用LoadData()方法?因为如果我不调用LoadData()方法,我就不会得到新的视图..嘿,Alex,谢谢你的建议,我从来没有想过,但我将来会记住它:)。感谢您的代码,我有一个问题:在LoadData()方法中,您将当前数据视图分配给Alle


我忘了!我还有一个问题,我编辑了我的帖子。你有办法解决这个问题吗?嘿,亚历克斯,谢谢你的建议,我从来没有想过,但我以后会记得的:)。感谢您的代码,我有一个问题:在LoadData()方法中,您将当前数据视图分配给AlleKunden。但是什么时候最好调用LoadData()方法?因为如果我不调用LoadData()方法,我就不会得到新的视图..嘿,Alex,谢谢你的建议,我从来没有想过,但我将来会记住它:)。感谢您的代码,我有一个问题:在LoadData()方法中,您将当前数据视图分配给AlleKunden。但是什么时候最好调用LoadData()方法?因为如果我不调用LoadData()方法,我将无法获得新视图。。
namespace StaticIPConfiger.Modelle {

class VModel {

    public List<string> AlleKunden {
        get {
            List<String> customerData = new List<String>();
            DatabaseConnection connection = new DatabaseConnection();
            SqlCommand getCustomers = new SqlCommand("Select c_name,l_name,a_town,a_pcode,a_street from dbo.AllCustomers", connection.Connection);
            connection.Connection.Open();
            getCustomers.ExecuteNonQuery();
            SqlDataReader reader = getCustomers.ExecuteReader();
            if(reader.HasRows) { }
                while (reader.Read()) {
                    customerData.Add(reader.GetString(0));
                }
            connection.Connection.Close();
            return customerData;
        }
    }
}
<Page x:Class="StaticIPConfiger.PageViewCustomers"
  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" 
  xmlns:local="clr-namespace:StaticIPConfiger"
  xmlns:localvm="clr-namespace:StaticIPConfiger.Modelle" 
  mc:Ignorable="d" 
  d:DesignHeight="300" d:DesignWidth="500"
  Title="PageViewCustomers">
<Page.Resources>
    <ObjectDataProvider x:Key="vm" ObjectType="{x:Type localvm:VModel}" />
</Page.Resources>

<Grid DataContext="{Binding}">
    <ListView Margin="8" Height="350" Width="500" 
         ItemsSource="{Binding}" DataContext="{Binding Path=AlleKunden}">
        <ListView.View>
            <GridView>
                <GridViewColumn DisplayMemberBinding="{Binding Path=c_name}" 
              Header="Name" Width="100"/>
                <GridViewColumn DisplayMemberBinding="{Binding Path=l_name}" 
              Header="Standort" Width="100"/>
                <GridViewColumn DisplayMemberBinding="{Binding Path=a_town}" 
              Header="Ort" Width="100"/>
                <GridViewColumn DisplayMemberBinding="{Binding Path=a_pcode}" 
              Header="PLZ" Width="100"/>
                <GridViewColumn DisplayMemberBinding="{Binding Path=a_street}" 
              Header="Straße" Width="100"/>
            </GridView>
        </ListView.View>
    </ListView>
</Grid>
class VModel
{
    public DataView AlleKunden
    {
        get
        {
            DataTable dt = new DataTable();
            DatabaseConnection connection = new DatabaseConnection();
            SqlDataAdapter adapter = new SqlDataAdapter();
            adapter.SelectCommand = new SqlCommand("Select c_name,l_name,a_town,a_pcode,a_street from dbo.AllCustomers", connection.Connection);
            adapter.Fill(dt);
            connection.Connection.Close();
            return dt.DefaultView;
        }
    }
}
<ListView Margin="8" Height="350" Width="500" ItemsSource="{Binding AlleKunden}">
    <ListView.View>
        <GridView>
            <GridViewColumn DisplayMemberBinding="{Binding Path=c_name}" Header="Name" Width="100"/>
            <GridViewColumn DisplayMemberBinding="{Binding Path=l_name}" Header="Standort" Width="100"/>
            <GridViewColumn DisplayMemberBinding="{Binding Path=a_town}" Header="Ort" Width="100"/>
            <GridViewColumn DisplayMemberBinding="{Binding Path=a_pcode}" Header="PLZ" Width="100"/>
            <GridViewColumn DisplayMemberBinding="{Binding Path=a_street}" Header="Straße" Width="100"/>
        </GridView>
    </ListView.View>
</ListView>
namespace WpfApplication1
{
    public class VModel
    {
        public VModel()
        {
            DataTable dt = new DataTable();
            using (SqlConnection connection = new SqlConnection("your connection string to the database..."))
            {
                SqlDataAdapter adapter = new SqlDataAdapter();
                adapter.SelectCommand = new SqlCommand("Select c_name, l_name, a_town, a_pcode, a_street from dbo.AllCustomers", connection);
                adapter.Fill(dt);
            }
            AlleKunden = dt.DefaultView;
        }

        public DataView AlleKunden { get; private set; }
    }
}
<Window x:Class="WpfApplication1.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:WpfApplication1"
        mc:Ignorable="d"
        Title="MainWindow" Height="350" Width="525">
    <Window.DataContext>
        <local:VModel />
    </Window.DataContext>
    <Grid>
        <ListView ItemsSource="{Binding AlleKunden}">
            <ListView.View>
                <GridView>
                    <GridViewColumn DisplayMemberBinding="{Binding Path=c_name}" Header="Name" Width="100"/>
                    <GridViewColumn DisplayMemberBinding="{Binding Path=l_name}" Header="Standort" Width="100"/>
                    <GridViewColumn DisplayMemberBinding="{Binding Path=a_town}" Header="Ort" Width="100"/>
                    <GridViewColumn DisplayMemberBinding="{Binding Path=a_pcode}" Header="PLZ" Width="100"/>
                    <GridViewColumn DisplayMemberBinding="{Binding Path=a_street}" Header="Straße" Width="100"/>
                </GridView>
            </ListView.View>
        </ListView>
    </Grid>
</Window>
public DataView AlleKunden
{
    get;
    private set;
}

// Use LoadData method anywhere in your ViewModel
private void LoadData()
{
    DataTable dt = new DataTable();
    try
    {
        DatabaseConnection connection = new DatabaseConnection();
        SqlDataAdapter adapter = new SqlDataAdapter();
        adapter.SelectCommand = new SqlCommand("Select c_name,l_name,a_town,a_pcode,a_street from dbo.AllCustomers", connection.Connection);
        adapter.Fill(dt);
        connection.Connection.Close();
        AlleKunden = dt.DefaultView;
    }
    catch (/* ... */)
    {

    }
}