小编Owa*_*ani的帖子

如何将Textbox的内容保存到文本文件中

我有一个包含一些内容的文本框.我还有一个按钮(SAVE),它打开FileSaveDialog并允许将内容保存在.txt文件中.

XAML:

<TextBox Height="93" IsReadOnly="True" Text="{Binding Path=ReadMessage, Mode=TwoWay}" Name="MessageRead" />

<Button Content="Save" Command="{Binding Path=SaveFileCommand}" Name="I2CSaveBtn" />
Run Code Online (Sandbox Code Playgroud)

视图模型:

private string _readMessage = string.Empty;
    public string ReadMessage
    {
        get
        {
            return _readMessage;
        }
        set
        {
            _readMessage = value;
            NotifyPropertyChanged("ReadMessage");
        }
    }

public static RelayCommand SaveFileCommand { get; set; }

private void RegisterCommands()
    {            
        SaveFileCommand = new RelayCommand(param => this.ExecuteSaveFileDialog());
    }
private void ExecuteSaveFileDialog()
    {
        //What To Do HERE???
    }
Run Code Online (Sandbox Code Playgroud)

我基本上需要的是阅读文本框的内容,打开文件保存对话框并将其存储在文本文件中以保存在我的系统中.

wpf textbox openfiledialog mvvm

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

如何在ListView内将两列的值连接成一列

我有一个.xaml文件,它有一个listview.Listview有2个项目,它们以下列方式绑定:

<ListView  Name="listView" ItemsSource="{Binding DeviceList}" SelectedItem="{Binding ConnectedDevice, Mode=TwoWay}" >
        <ListView.View>
            <GridView>
                <GridViewColumn Width="300" Header="Name" DisplayMemberBinding="{Binding Description}" />
                <GridViewColumn Width="240" Header="Connection Status" DisplayMemberBinding="{Binding DeviceName}" />
            </GridView>
        </ListView.View>
    </ListView>
Run Code Online (Sandbox Code Playgroud)

这两种描述设备名称是ModelClass.In我ViewModel类的一部分,我能够从我已连接硬件提取设备名称及说明.

    public ObservableCollection<ComDeviceInfo> DeviceList
    {
        get { return comDevices; }
        set
        {
            comDevices = value;
            NotifyPropertyChanged("DeviceList");
        }
    }

    public ComDeviceInfo ConnectedDevice
    {
        get { return connectedDevice; }
        set
        {
            connectedDevice = value;
            NotifyPropertyChanged("ConnectedDevice");
        }
    }        

    //Called Inside Constructor
    private void checkForDevicesTimer_Elapsed(Object source, ElapsedEventArgs e)
    {            
        DeviceList = ComDeviceManagement.FindDevices();            
    } …
Run Code Online (Sandbox Code Playgroud)

c# wpf listview mvvm

0
推荐指数
1
解决办法
3694
查看次数

标签 统计

mvvm ×2

wpf ×2

c# ×1

listview ×1

openfiledialog ×1

textbox ×1