c# wpf log 调试 输出窗口
需求
其实我们只是简单的入门调试,只需要很简单的输出
真不需要log4net, expression等等比较长期地,跨度比较大的日志系统
而且这些日志系统接入也比较麻烦
有没办法做一个简单的log输出呢,官方visual studio肯定自带
我们需要的只是在视图输出,有一些内容即可
我们需要的只是,点击左边栏,刷新右边内容页。。。
嗯,稍微说一下wpf 的结构吧 :
UI可视化 -- 底层是xml数据结构 -- 映射成UI 和逻辑C#代码
wpf就是这普普的三层结构(中间的关联我忘了)
所以首先,能在不运行的情况下,能看到下面这个UI可视化界面
( 好像,运行(调试)时,就会把这个界面推到 Appliation 前台了,就只能看到xml和代码了)
在非运行时,通过中文 TextBlock,定位和找到左边栏的xml文件,添加点击事件
加上 MouseLeftButtonUp 后如下
<StackPanel x:Name="PanRyuModsManager" Height="30" Orientation="Horizontal" VerticalAlignment="Center" Margin="0 10 0 0" MouseLeftButtonUp ="UIElement_OnMouseUp"><TextBlock Text="" FontSize="16" FontFamily="/#iconfont" Foreground="#666666" VerticalAlignment="Center"/><TextBlock Text="如龙Mods管理" Margin="10 0 0 0" VerticalAlignment="Center" Foreground="#666666"/></StackPanel><StackPanel x:Name="PanRyuMv" Height="30" Orientation="Horizontal" VerticalAlignment="Center" Margin="0 10 0 0"><TextBlock Text="" FontSize="16" FontFamily="/#iconfont" Foreground="#666666" VerticalAlignment="Center"/><TextBlock Text="如龙7MV" Margin="10 0 0 0" VerticalAlignment="Center" Foreground="#666666"/></StackPanel>
在主代码类,写上
namespace wof
{/// <summary>/// MainWindow.xaml 的交互逻辑/// </summary>public partial class MainWindow : Window{public MainWindow(){InitializeComponent();}void UIElement_OnMouseUp(object sender, MouseButtonEventArgs e) {// var tag = (sender as TextBlock).Tag;Console.WriteLine("fffffffffff");}}
}
如此一来,我们就很快能调试定位到,点击事件了
结果如下