本文介绍了读取文本文件并以xaml显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个代码读取我的app文件夹中的文本文件并将其显示在消息框中,

每当用户点击列表中的项目并且它正常工作时。



CustomMessageBox cmb;

private void Day1(对象发送者,System.Windows.Input.GestureEventArgs e)

{

//创建新的Stack面板

StackPanel sp = new StackPanel(){Orientation = System.Windows.Controls.Orientation.Vertical};



//从文件中获取政策文本

string devotion = getDevotion335();



//创建新标签

TextBlock tb = new TextBlock()

{

Text = devotion,

TextWrapping = TextWrapping.Wrap,

FontSize = 20,



};



//创建新的滚动视图呃

ScrollViewer sv = new ScrollViewer()

{

VerticalScrollBarVisibility = ScrollBarVisibility.Auto,

Height = 700 ,

};



//在滚动查看器中添加texblock

sv.Content = tb;



//将控件添加到堆栈面板

sp.Children.Add(sv);



cmb = new CustomMessageBox()

{

//设置其内容

内容= sp,

Opacity = 15.0,





//消息框左按钮按钮

LeftButtonContent =返回,





};



//显示信息盒子......

cmb.Show();

}



私有字符串getDevotion335()

{

使用(StreamReader s = new StreamReader(Devotions / Devotion335.txt))

{

返回s.ReadToEnd();

}

}



我希望它不会在消息框中显示,而是希望它显示在xaml页面中。

我需要对代码进行哪些重大更改才能帮助



提前感谢您的回复

解决方案

I have this code which reads text files in my app folder and displayed it in a messagebox,
whenever the user clicks an item in a list and it's working fine.

CustomMessageBox cmb;
private void Day1(object sender, System.Windows.Input.GestureEventArgs e)
{
// create new Stack panel
StackPanel sp = new StackPanel() { Orientation = System.Windows.Controls.Orientation.Vertical };

//get policy text from file
string devotion = getDevotion335();

//Create new label
TextBlock tb = new TextBlock()
{
Text = devotion,
TextWrapping = TextWrapping.Wrap,
FontSize = 20,

};

//Create new Scroll viewer
ScrollViewer sv = new ScrollViewer()
{
VerticalScrollBarVisibility = ScrollBarVisibility.Auto,
Height = 700,
};

// add texblock in scroll viewer
sv.Content = tb;

//Add the controls to stack panel
sp.Children.Add(sv);

cmb = new CustomMessageBox()
{
// Set its content
Content = sp,
Opacity = 15.0,


// Left button of message box Button
LeftButtonContent = "Back",


};

//Show the message box...
cmb.Show();
}

private string getDevotion335()
{
using (StreamReader s = new StreamReader("Devotions/Devotion335.txt"))
{
return s.ReadToEnd();
}
}

Instead of displaying it in a messagebox i will like it to be displayed in a xaml page.
What are major changes i need to make to the code kindly help

Thank you in advance and reply soon

解决方案


这篇关于读取文本文件并以xaml显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 21:11