当前位置: 编程技术>.net/c#/asp.net
本页文章导读:
▪通过 IHttpModule interface 来实现 aps.net 页面部分 全局更改 有时候。比如。在所有页面下方实现一个输出当前时间 。方便查看时间mono 测试已过。其他未测试 这时候可以通过 IHttpModule 接口来全局实现。IHttpModule --->request ---> Http Mo.........
▪WPF ListView实现DataGrid同样的效果 <ListView><ListView.View><GridView><!--表示一种视图模式,该模式以列的形式显示ListView控件的数据项源文档 <http://msdn.microsoft.com/query/dev10.query?appId=Dev10IDEF1&l=ZH-CN&k=k(SYSTEM.WINDOWS.........
▪WPF TextBox输入显示提示 在网上支付输入银行卡的时候,经常看到输入的数字会放大和提示。 下面是WPF版的一个例子。 Code public class ZoomTextTooltip : FrameworkElement { public object ZoomText { get { return (obje.........
[1]通过 IHttpModule interface 来实现 aps.net 页面部分 全局更改
有时候。比如。在所有页面下方实现一个输出当前时间 。方便查看时间
mono 测试已过。其他未测试
这时候可以通过 IHttpModule 接口来全局实现。
IHttpModule --->request ---> Http Module 来挂钩
so:
1.配置文件里面,指向这个类。当request访问的时候。初始化这个类
<httpModules>
<add name="SimpleModule"type="SimpleModule, App_code"/>
</httpModules>
2 simpleModule 首先要继承IHttpModule .然后必须要 Init和Dispose 实现
public class SimpleModule : IHttpModule
{
private HttpApplication objApplication = null;
public void Dispose()
{
}
public void Init(System.Web.HttpApplication context)
{
objApplication = context;
context.EndRequest += new EventHandler(context_EndRequest);
}
void context_EndRequest(object sender, EventArgs e)
{
string message =
string.Format("<br/>现在时间为{0}", System.DateTime.Now.ToString());
objApplication.Context.Response.Write(message);
}
}
{
private HttpApplication objApplication = null;
public void Dispose()
{
}
public void Init(System.Web.HttpApplication context)
{
objApplication = context;
context.EndRequest += new EventHandler(context_EndRequest);
}
void context_EndRequest(object sender, EventArgs e)
{
string message =
string.Format("<br/>现在时间为{0}", System.DateTime.Now.ToString());
objApplication.Context.Response.Write(message);
}
}
这时,访问任何页面,页面下面就会出现时间。
本文链接
[2]WPF ListView实现DataGrid同样的效果
<ListView>
<ListView.View>
<GridView>
<!--
表示一种视图模式,该模式以列的形式显示ListView控件的数据项
源文档 <http://msdn.microsoft.com/query/dev10.query?appId=Dev10IDEF1&l=ZH-CN&k=k(SYSTEM.WINDOWS.CONTROLS.GRIDVIEW);k(VS.XAMLEDITOR);k(SOLUTIONITEMSPROJECT);k(TargetFrameworkMoniker-%22.NETFRAMEWORK%2cVERSION%3dV4.0%22)&rd=true> -->
</GridView>
<ListView.View>
</ListView>
本文链接
[3]WPF TextBox输入显示提示
在网上支付输入银行卡的时候,经常看到输入的数字会放大和提示。
下面是WPF版的一个例子。
Code public class ZoomTextTooltip : FrameworkElement
{
public object ZoomText
{
get { return (object)GetValue(ZoomTextProperty); }
set { SetValue(ZoomTextProperty, value); }
}
// Using a DependencyProperty as the backing store for ZoomText. This enables animation, styling, binding, etc...
public static readonly DependencyProperty ZoomTextProperty =
DependencyProperty.Register("ZoomText", typeof(object), typeof(ZoomTextTooltip), new UIPropertyMetadata(null,
(o, args) =>
{
var textBox = args.NewValue as TextBox;
if (textBox == null)
return;
var zoomTextTooltip = o as ZoomTextTooltip;
if (zoomTextTooltip == null)
return;
var popup = new Popup();
var textBlock = new TextBlock
{
Text = textBox.Text,
FontWeight = FontWeights.Bold,
FontSize = zoomTextTooltip.CustomFontSize,
Background = zoomTextTooltip.CustomBackground,
Foreground = zoomTextTooltip.CustomForeground
};
var binding = new Binding();
binding.Source = textBox;
binding.Path = new PropertyPath("IsKeyboardFocused");
BindingOperations.SetBinding(popup, Popup.StaysOpenProperty, binding);
var inputText = zoomTextTooltip.AddBlockString(textBox.Text.Trim(), zoomTextTooltip.BlockCount);
textBlock.Text = inputText;
popup.Child = textBlock;
textBox.GotFocus += (sender, eventArgs) =>
{
popup.PlacementTarget = textBox;
popup.Placement = PlacementMode.Top;
popup.IsOpen = true;
};
textBox.TextChanged += (sender, eventArgs) =>
{
var addBlockString = zoomTextTooltip.AddBlockString(textBox.Text.Trim(), zoomTextTooltip.BlockCount);
textBlock.Text = addBlockString;
};
textBox.LostFocus += (sender, eventArgs) =>
{
popup.IsOpen = false;
};
}
));
//字符串截取
private string AddBlockString(string input, int count)
{
if (count == 0)
return input;
var blockinput = string.Empty;
var length = Math.Ceiling((double)input.Length / count);
for (int i = 0; i < length; i++)
{
var firstStart = i * count;
var endString = input.Length - firstStart;
if (endString < count)
{
blockinput += input.Substring(firstStart);
}
else
{
blockinput += input.Substring(firstStart, count);
blockinput += " ";
}
}
return blockinput;
}
public double CustomFontSize
{
get { return (double)GetValue(CustomFontSizeProperty); }
set { SetValue(CustomFontSizeProperty, value); }
}
public static readonly DependencyProperty CustomFontSizeProperty =
DependencyProperty.Register("CustomFontSize", typeof(double), typeof(ZoomTextTooltip), new UIPropertyMetadata(12.0));
public Brush CustomBackground
{
get { return (Brush)GetValue(CustomBackgroundProperty); }
set { SetValue(CustomBackgroundProperty, value); }
}
public static readonly DependencyProperty CustomBackgroundProperty =
DependencyProperty.Register("CustomBackground", typeof(Brush), typeof(ZoomTextTooltip), new UIPropertyMetadata(Brushes.White));
public Brush CustomForeground
{
get { return (Brush)GetValue(CustomForegroundProperty); }
set { SetValue(CustomForegroundProperty, value); }
}
public static readonly DependencyProperty CustomForegroundProperty =
DependencyProperty.Register("CustomForeground", typeof(Brush), typeof(ZoomTextTooltip), new UIPropertyMetadata(Brushes.Black));
public int BlockCount
{
get { return (int)GetValue(BlockCountProperty); }
{
public object ZoomText
{
get { return (object)GetValue(ZoomTextProperty); }
set { SetValue(ZoomTextProperty, value); }
}
// Using a DependencyProperty as the backing store for ZoomText. This enables animation, styling, binding, etc...
public static readonly DependencyProperty ZoomTextProperty =
DependencyProperty.Register("ZoomText", typeof(object), typeof(ZoomTextTooltip), new UIPropertyMetadata(null,
(o, args) =>
{
var textBox = args.NewValue as TextBox;
if (textBox == null)
return;
var zoomTextTooltip = o as ZoomTextTooltip;
if (zoomTextTooltip == null)
return;
var popup = new Popup();
var textBlock = new TextBlock
{
Text = textBox.Text,
FontWeight = FontWeights.Bold,
FontSize = zoomTextTooltip.CustomFontSize,
Background = zoomTextTooltip.CustomBackground,
Foreground = zoomTextTooltip.CustomForeground
};
var binding = new Binding();
binding.Source = textBox;
binding.Path = new PropertyPath("IsKeyboardFocused");
BindingOperations.SetBinding(popup, Popup.StaysOpenProperty, binding);
var inputText = zoomTextTooltip.AddBlockString(textBox.Text.Trim(), zoomTextTooltip.BlockCount);
textBlock.Text = inputText;
popup.Child = textBlock;
textBox.GotFocus += (sender, eventArgs) =>
{
popup.PlacementTarget = textBox;
popup.Placement = PlacementMode.Top;
popup.IsOpen = true;
};
textBox.TextChanged += (sender, eventArgs) =>
{
var addBlockString = zoomTextTooltip.AddBlockString(textBox.Text.Trim(), zoomTextTooltip.BlockCount);
textBlock.Text = addBlockString;
};
textBox.LostFocus += (sender, eventArgs) =>
{
popup.IsOpen = false;
};
}
));
//字符串截取
private string AddBlockString(string input, int count)
{
if (count == 0)
return input;
var blockinput = string.Empty;
var length = Math.Ceiling((double)input.Length / count);
for (int i = 0; i < length; i++)
{
var firstStart = i * count;
var endString = input.Length - firstStart;
if (endString < count)
{
blockinput += input.Substring(firstStart);
}
else
{
blockinput += input.Substring(firstStart, count);
blockinput += " ";
}
}
return blockinput;
}
public double CustomFontSize
{
get { return (double)GetValue(CustomFontSizeProperty); }
set { SetValue(CustomFontSizeProperty, value); }
}
public static readonly DependencyProperty CustomFontSizeProperty =
DependencyProperty.Register("CustomFontSize", typeof(double), typeof(ZoomTextTooltip), new UIPropertyMetadata(12.0));
public Brush CustomBackground
{
get { return (Brush)GetValue(CustomBackgroundProperty); }
set { SetValue(CustomBackgroundProperty, value); }
}
public static readonly DependencyProperty CustomBackgroundProperty =
DependencyProperty.Register("CustomBackground", typeof(Brush), typeof(ZoomTextTooltip), new UIPropertyMetadata(Brushes.White));
public Brush CustomForeground
{
get { return (Brush)GetValue(CustomForegroundProperty); }
set { SetValue(CustomForegroundProperty, value); }
}
public static readonly DependencyProperty CustomForegroundProperty =
DependencyProperty.Register("CustomForeground", typeof(Brush), typeof(ZoomTextTooltip), new UIPropertyMetadata(Brushes.Black));
public int BlockCount
{
get { return (int)GetValue(BlockCountProperty); }
最新技术文章:
 
站内导航:
特别声明:169IT网站部分信息来自互联网,如果侵犯您的权利,请及时告知,本站将立即删除!