我有一个CheckBoxList控件,我想让用户检查至少一个盒子,如果他们检查每一个,或3个,甚至只是一个,都没关系.
本着asp.net的验证控件的精神,我可以使用什么来强制执行此操作?我也在使用Ajax验证扩展器,所以如果它看起来像其他控件,而不是代码隐藏中的一些俗气的服务器验证方法,那将会很好.
<asp:CheckBoxList RepeatDirection="Horizontal" RepeatLayout="Table" RepeatColumns="3" ID="ckBoxListReasons" runat="server">
<asp:ListItem Text="Preliminary Construction" Value="prelim_construction" />
<asp:ListItem Text="Final Construction" Value="final_construction" />
<asp:ListItem Text="Construction Alteration" Value="construction_alteration" />
<asp:ListItem Text="Remodel" Value="remodel" />
<asp:ListItem Text="Color" Value="color" />
<asp:ListItem Text="Brick" Value="brick" />
<asp:ListItem Text="Exterior Lighting" Value="exterior_lighting" />
<asp:ListItem Text="Deck/Patio/Flatwork" Value="deck_patio_flatwork" />
<asp:ListItem Text="Fence/Screening" Value="fence_screening" />
<asp:ListItem Text="Landscape - Front" Value="landscape_front" />
<asp:ListItem Text="Landscape - Side/Rear" Value="landscape_side_rear" />
<asp:ListItem Text="Other" Value="other" />
</asp:CheckBoxList>
Run Code Online (Sandbox Code Playgroud) 我有一个标题窗口.当用户从下拉列表中选择一个选项时,标题图像可以改变.问题是当图像加载时,它是模糊的,拉伸的和像素化的.这些是我正在使用的PNG文件,它们在动态设置源之前看起来很好.
这是我用来更改图像源代码的代码.
string strUri2 = String.Format(@"pack://application:,,,/MyAssembly;component/resources/main titles/{0}", CurrenSelection.TitleImage);
Stream iconStream2 = App.GetResourceStream(new Uri(strUri2)).Stream;
imgTitle.Source = HelperFunctions.returnImage(iconStream2);
Run Code Online (Sandbox Code Playgroud)
这是辅助函数.
public static BitmapImage returnImage(Stream iconStream)
{
Bitmap brush = new Bitmap(iconStream);
System.Drawing.Image img = brush.GetThumbnailImage(brush.Height, brush.Width, null, System.IntPtr.Zero);
var imgbrush = new BitmapImage();
imgbrush.BeginInit();
imgbrush.StreamSource = ConvertImageToMemoryStream(img);
imgbrush.CreateOptions = BitmapCreateOptions.PreservePixelFormat;
imgbrush.EndInit();
var ib = new ImageBrush(imgbrush);
return imgbrush;
}
public static MemoryStream ConvertImageToMemoryStream(System.Drawing.Image img)
{
var ms = new MemoryStream();
img.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
return ms;
}
Run Code Online (Sandbox Code Playgroud)
和XAML
<Image x:Name="imgTitle" HorizontalAlignment="Left" VerticalAlignment="Bottom" Grid.Column="1" Grid.Row="1" Stretch="None" …Run Code Online (Sandbox Code Playgroud) 我正在尝试在我的应用程序中添加自定义字体作为资源.我在应用程序中有一个"CustomFont"目录,其中的所有字体都设置为"Resource"
<Window.Resources>
<Style x:Key="Gotham-XLight">
<Setter Property="TextElement.FontFamily"
Value="/CustomFonts;Component/#Gotham-XLight" />
</Style>
</Window.Resources>
Run Code Online (Sandbox Code Playgroud)
然后在我的TextBlock上我有这个:(在网格内)
<TextBlock x:Name="TimeTextBlock" Style="{DynamicResource Gotham-XLight}"
TextAlignment="Center" FontSize="25" FontWeight="Bold"
Foreground="White" Text="TextBlockTimer"
Margin="105,242.974,0,226.975" HorizontalAlignment="Left"
Width="221.919" />
Run Code Online (Sandbox Code Playgroud)
但是我没有像人们说的那样看到我的字体.难道我做错了什么?
还在这里解决问题.我甚至不是很接近,但无论如何......我有一个从Xcode创建的TabBar应用程序.它有效我有三个标签视图,我知道如何操纵,等等.
我想在这整个事情面前放一个'登录'nib文件,要求用户回答(现在硬编码)用户名和密码.如果你做对了,那么,渲染标签部分,允许他们点击.
我有另一个我编写过的用户名和密码部分的应用程序,我在从那里获取逻辑时遇到了麻烦,并把它放在了TabApplication的前面.
有人有什么建议吗?
我有一个ListBox水平滚动图像.
我有以下XAML我用混合来创建它.它最初有斧头:关键Style TaregetType在线,MSDN说要删除它,因为我得到了错误.现在我收到这个错误:
Error 3 Operation is not valid while ItemsSource is in use. Access and modify elements with ItemsControl.ItemsSource instead.
我不明白如何以这种方式应用所有这些垃圾,我尝试了几件事,没有任何工作.
我的目标是让所选项目的背景为白色,而不是蓝色.对于这么小的东西来说似乎很多工作!
谢谢.
<ListBox ItemsSource="{Binding Source={StaticResource WPFApparelCollection}}"
Grid.Row="1" Margin="2,26,2,104" ScrollViewer.VerticalScrollBarVisibility="Hidden"
ScrollViewer.HorizontalScrollBarVisibility="Hidden" SelectionMode="Single"
x:Name="list1" MouseLeave="List1_MouseLeave" MouseMove="List1_MouseMove" Style="{DynamicResource ListBoxStyle1}" >
<Style TargetType="{x:Type ListBoxItem}">
<Setter Property="Background" Value="Transparent"/>
<Setter Property="HorizontalContentAlignment" Value="{Binding Path=HorizontalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}"/>
<Setter Property="VerticalContentAlignment" Value="{Binding Path=VerticalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}"/>
<Setter Property="Padding" Value="2,0,0,0"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ListBoxItem}">
<Border x:Name="Bd" SnapsToDevicePixels="true" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding …Run Code Online (Sandbox Code Playgroud) 好吧,在我的ListBox滚动图像w /文本等等saga继续.当我单击其中一个项目以选择它时,它会运行一个过程来打开Web浏览器并转到特定的URL.我现在遇到的问题是,当WPF应用程序失去焦点,并且Web浏览器打开时,在列表框内单击的项目将变为白色.这是整个ListBox XAML.我已将所选项目设置为透明,这是否与WPF应用程序失去焦点有关?
有什么我可以添加运行该过程的代码来打开Web浏览器以将焦点设置回WPF应用程序?
谢谢.
<ListBox ItemsSource="{Binding Source={StaticResource WPFApparelCollection}}" Margin="61,-8,68,-18" ScrollViewer.VerticalScrollBarVisibility="Hidden" ScrollViewer.HorizontalScrollBarVisibility="Hidden" SelectionMode="Single" x:Name="list1" MouseLeave="List1_MouseLeave" MouseMove="List1_MouseMove" Style="{DynamicResource ListBoxStyle1}" Background="Transparent" BorderThickness="0">
<ListBox.ItemContainerStyle>
<Style TargetType="{x:Type ListBoxItem}">
<Setter Property="Background" Value="Transparent" />
<Setter Property="HorizontalContentAlignment" Value="{Binding Path=HorizontalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}" />
<Setter Property="VerticalContentAlignment" Value="{Binding Path=VerticalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}" />
<Setter Property="Padding" Value="20,10,20,10" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ListBoxItem}">
<Border x:Name="Bd" SnapsToDevicePixels="true" Background="Transparent" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Padding="{TemplateBinding Padding}">
<ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsSelected" Value="true">
<Setter Property="Background" TargetName="Bd" …Run Code Online (Sandbox Code Playgroud) 我有一个存储一些文件的SQL数据库.
用户可以登录该应用程序,并查看其文档列表.
当在文档的gridview中单击链接按钮下载时,我从数据库中获取文件,将其写入文件系统,然后执行此代码.
System.IO.FileInfo file = new System.IO.FileInfo(System.Configuration.ConfigurationManager.AppSettings["UploadPath"] + DocumentName);
Response.Clear();
Response.ClearContent();
Response.ClearHeaders();
Response.Cookies.Clear();
Response.Cache.SetCacheability(HttpCacheability.Private);
Response.CacheControl = "private";
Response.Charset = System.Text.UTF8Encoding.UTF8.WebName;
Response.ContentEncoding = System.Text.UTF8Encoding.UTF8;
Response.AppendHeader("Content-Length", file.Length.ToString());
Response.AppendHeader("Pragma","cache");
Response.AppendHeader("Expires", "60");
Response.ContentType = GetContentType(file.Extension);
Response.AppendHeader("Content-Disposition",
"inline; " +
"filename=\"" + file.Name + "\"; " +
"size=" + file.Length.ToString() + "; " +
"creation-date=" + DateTime.Now.ToString("R") + "; " +
"modification-date=" + DateTime.Now.ToString("R") + "; " +
"read-date=" + DateTime.Now.ToString("R"));
Run Code Online (Sandbox Code Playgroud)
我的GetContentType()方法只返回我允许的文件的相应文件类型"application/pdf,application/msw0rd等.
我的问题是,当文件被保存时,它是网页本身,而不是文件系统中的文件.在谷歌浏览器中,它在文件名的末尾添加.htm扩展名,我猜是因为它知道它是一个网页?
无论如何,一个伟大的第一步是获取实际文件,而不是他们所坐的HTML网页的副本!
谢谢.
考虑以下代码,我有一个文本块,它是WPF中的"开/关"按钮.它只是一个椭圆内的文字,表示ON/OFF.当用户单击按钮并按住鼠标一秒钟时,如果设备尚未通电,它将执行"打开设备"代码.如果用户按住ON/OFF按钮三秒钟或更长时间(保持鼠标左键保持向下),设备将关闭.
我错过了几个问题.1.尽管计时器已启动,但在按住鼠标按钮时不会触发tick事件.2.尽管按下按钮,do/while循环仍然不会退出
谢谢!
public int TimerCount = 0;
private void ButtonPressTimer(object sender, EventArgs e)
{
TimerCount = TimerCount + 1;
}
private void txtBlockOnOff_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
var buttonPressTimer = new DispatcherTimer(new TimeSpan(0, 0, 0, 1), DispatcherPriority.Normal, ButtonPressTimer, this.Dispatcher);
do
{
if (!buttonPressTimer.IsEnabled)
buttonPressTimer.Start();
}
while (e.ButtonState == MouseButtonState.Pressed);
buttonPressTimer.Stop();
if (TimerCount >= 3)
{
//do something here
}
else
{
//do something different here
}
}
Run Code Online (Sandbox Code Playgroud) 我有以下正则表达式:
(?!^[&#]*$)^([A-Za-z0-9-'.,&@:?!()$#/\\]*)$
Run Code Online (Sandbox Code Playgroud)
所以允许AZ,aZ,0-9和这些特殊的字符 '.,&@:?!()$#/\
如果在此字符串中的任何位置遇到以下字符集,我想不匹配:
&#
Run Code Online (Sandbox Code Playgroud)
当我使用""作为输入运行此正则表达式时,它与我的模式不匹配,我收到错误,很棒.当我运行正则表达式时'.,&@:?!()$#/\ABC123它与我的模式匹配,没有错误.
但是当我运行时:
'.,&#@:?!()$#/\ABC123
Run Code Online (Sandbox Code Playgroud)
它也没有错误.我在检查序列时遇到了问题.
有人能告诉我我做错了什么,我对这些事情并不好.
给定以下RegEx表达式,在regexlib.com上使用字符串"2rocks"进行测试会产生"匹配".但是,在我的.NET应用程序中,它导致正则表达式验证程序抛出验证错误.
^(?=.*[A-Za-z])[a-zA-Z0-9@\-_\+\.]{6,32}$
Run Code Online (Sandbox Code Playgroud)
如果我在我的应用程序和regexlib.com中将字符串更改为"rocks2",我会在两个地方都匹配.
目标是有一个正则表达式,要求字符串长度在6-32个字符之间,并允许AZ,az,数字和正则表达式中包含的其他特殊字符,强制至少一个字母.
这是ASP标记,我完全糊涂了.
<asp:regularexpressionvalidator
id=vldRegEx_LoginID
runat="server"
ErrorMessage="Regex Error Message"
Display="Dynamic"
ControlToValidate="txtLoginID"
ValidationExpression="^(?=.*[A-Za-z])[a-zA-Z0-9@\-_\+\.]{6,32}$">
<img src="images/error.gif" border="0">
</asp:regularexpressionvalidator>
Run Code Online (Sandbox Code Playgroud) 我需要加入以下正则表达式,我写这些很可怕:
xx12ab - valid
x12345 - invalid
xxxxx1 - invalid
xxx123 - valid
Run Code Online (Sandbox Code Playgroud)
我需要一个6个字符的字符串,它至少有2个字母字符和2个数字字符,仅限于字符串中的字母/数字.
谢谢.