我一直在寻找这个。正如标题所说,有没有办法让XamlWriter
阅读文本框的内容以及文本框本身的定义?使用MVVM时,XamlWriter可以读取文本框内容吗?
的文本框不直接进入Xaml
,因为他们已经绑定到MVVM
模式,在运行时。目前,XamlWriter
只是保存没有内容的文本框。
示例代码保存视图,但没有文本框的内容:
string mystrXAML = XamlWriter.Save(StackPanelContent);
string name = txtname.Text;
FileStream fs = File.Create(String.Format(@"C:\Desktop\" + name + ".txt"));
StreamWriter sw = new StreamWriter(fs);
sw.Write(mystrXAML);
sw.Close();
fs.Close();
编辑:
已经花了很多的时间去思考和研究如何做到这一点仍然无法找到正确的答案。这是我的XAML代码和它仍然没有保存文本框的内容,这是因为它们绑定(是我研究)
XAML:
<ListView ItemsSource="{Binding Title}" ItemTemplate="{DynamicResource Template}">
<ListView.ItemContainerStyle>
<Style>
<Setter Property="FrameworkElement.Margin" Value="20,20,0,0"/>
</Style>
</ListView.ItemContainerStyle>
<ListView.Resources>
<DataTemplate x:Key="Template">
<TextBox Text="{Binding .}" Width="200" HorizontalAlignment="Left" />
</DataTemplate>
</ListView.Resources>
</ListView>
<ListView x:Name="QuestionList" ItemsSource="{Binding Question}" ItemTemplate {DynamicResource Template}">
<ListView.ItemContainerStyle>
<Style>
<Setter Property="FrameworkElement.Margin" Value="40,20,0,0"/>
</Style>
</ListView.ItemContainerStyle>
<ListView.Resources>
<DataTemplate x:Key="Template">
<TextBox Text="{Binding .}" Width="200" HorizontalAlignment="Left"/>
</DataTemplate>
</ListView.Resources>
</ListView>
对不起,如果我的反应不好,我知道有些问题我已经发布了很多关于,但我承担的事情是我是一个新的开发人员要求_advice_,而不是让某人为我**代码**。我已阅读完整答案。首先,我认为它没有通过的原因现在文本框的内容是因为绑定了?其次,你救救内容到数据库中,但是当你加载了该浏览一遍,他们如何知道什么文本框获得放回。感谢您的答复。 – user3157821
“开始听的是知道他们在说什么的人。” @谢里登,我可以给你买啤酒吗? – Gusdor