以下WPF UserControl称为DataTypeWholeNumber,它可以正常工作.
现在我想创建一个名为DataTypeDateTime和DataTypeEmail等的UserControl .
许多依赖属性将由所有这些控件共享,因此我想将它们的公共方法放入BaseDataType中,并使每个UserControl都继承自此基类型.
但是,当我这样做时,我得到错误:部分声明可能没有不同的基类.
那么如何使用UserControls实现继承,以便共享功能全部在基类中?
using System.Windows;
using System.Windows.Controls;
namespace TestDependencyProperty827.DataTypes
{
public partial class DataTypeWholeNumber : BaseDataType
{
public DataTypeWholeNumber()
{
InitializeComponent();
DataContext = this;
//defaults
TheWidth = 200;
}
public string TheLabel
{
get
{
return (string)GetValue(TheLabelProperty);
}
set
{
SetValue(TheLabelProperty, value);
}
}
public static readonly DependencyProperty TheLabelProperty =
DependencyProperty.Register("TheLabel", typeof(string), typeof(BaseDataType),
new FrameworkPropertyMetadata());
public string TheContent
{
get
{
return (string)GetValue(TheContentProperty);
} …Run Code Online (Sandbox Code Playgroud) EditPad Lite有一个很好的功能(CTRL- E,CTRL- I),它会在您的代码中插入时间戳,例如"2008-09-11 10:34:53".
在Vim中获得此功能的最佳方法是什么?
(我在Linux服务器上通过SSH使用Vim 6.1.在目前的情况下,我们中的许多人共享登录,所以如果有另一种内置方式来获取时间戳,我不想在主目录中创建缩写. )
我经常使用Shift+ F7来在源视图和设计视图之间切换.
有没有人知道在源文件及其代码隐藏文件之间切换的热键,例如(Default.aspx和Default.aspx.cs)之间?
我怎么能够:
这是代码:
<ListView Name="lstCustomers" ItemsSource="{Binding Path=Collection}">
<ListView.View>
<GridView>
<GridViewColumn Header="ID" DisplayMemberBinding="{Binding Id}" Width="40"/>
<GridViewColumn Header="First Name" DisplayMemberBinding="{Binding FirstName}" Width="100" />
<GridViewColumn Header="Last Name" DisplayMemberBinding="{Binding LastName}"/>
</GridView>
</ListView.View>
</ListView>
Run Code Online (Sandbox Code Playgroud)
感谢Kjetil,GridViewColumn.CellTemplate运行良好,自动宽度当然有效但是当使用长于列宽的数据更新ObservativeCollection"Collection"时,列大小不会自行更新,因此这只是一个解决方案.初始显示数据:
<ListView Name="lstCustomers" ItemsSource="{Binding Path=Collection}">
<ListView.View>
<GridView>
<GridViewColumn Header="ID" Width="Auto">
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding Id}" TextAlignment="Right" Width="40"/>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Header="First Name" DisplayMemberBinding="{Binding FirstName}" Width="Auto" />
<GridViewColumn Header="Last Name" DisplayMemberBinding="{Binding LastName}" Width="Auto"/>
</GridView>
</ListView.View>
</ListView>
Run Code Online (Sandbox Code Playgroud) 在下面的例子中,我有一个ListBox,里面有几十个字体名称.
我原以为它会自动在它上面有一个垂直滚动条,这样你就可以选择任何字体,而不仅仅是列表中的第一个字体,但事实并非如此.
所以我添加了一个"ScrollViewer"并在右侧放置了一个"滚动条区域",但滚动条区域中没有滚动条,因此您可以滚动(!).
为什么滚动条不是自动的,如何强制滚动条?
<StackPanel Name="stack1">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="2*"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
</Grid.RowDefinitions>
<ScrollViewer>
<ListBox Grid.Row="0" Name="lstFonts" Margin="3" ItemsSource="{x:Static Fonts.SystemFontFamilies}"/>
</ScrollViewer>
</Grid>
</StackPanel>
Run Code Online (Sandbox Code Playgroud) 当您单击一个复选框时,我希望消息缓慢淡入.
为什么.fadeIn()在这个例子中不起作用?
HTML:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8"/>
<title>Text XHTML Page</title>
<link href="css/main.css" rel="stylesheet" type="text/css" media="all"/>
<script type="text/javascript" src="http://www.google.com/jsapi"></script>
<script type="text/javascript" src="javascript/main.js"></script>
</head>
<body>
<div class="checkboxList">
<div class="title">Languages:</div>
<div class="row"><input class="checkbox" type="checkbox"/><span class="label">Ruby</span></div>
<div class="row"><input type="checkbox"/><span class="label">PHP</span></div>
<div class="row"><input type="checkbox"/><span class="label">C#</span></div>
<div class="row"><input type="checkbox"/><span class="label">Python</span></div>
<div class="row"><input type="checkbox"/><span class="label">JavaScript</span></div>
</div>
<p id="message"></p>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
JavaScript的:
google.load("jquery", "1.3.2");
//run when page is loaded
google.setOnLoadCallback(function() {
$('.checkboxList .row').css('color','red');
$('.checkboxList input').attr('checked', true);
$('.checkboxList input').bind('click', …Run Code Online (Sandbox Code Playgroud) 在下面的WPF XAML中,ScrollViewer不起作用(它显示滚动条但不能滚动,内容从窗口向下移动到底部).
我可以将外部StackPanel更改为Grid,它将起作用.
但是,在我复制以下代码的应用程序中,我需要一个外部StackPanel.我需要对StackPanel做什么才能让ScrollViewer显示一个可用的滚动条?例如VerticalAlignment ="Stretch"Height ="Auto"不起作用.
<StackPanel>
<ScrollViewer>
<StackPanel>
<TextBlock Text="This is a test"/>
<TextBlock Text="This is a test"/>
<TextBlock Text="This is a test"/>
<TextBlock Text="This is a test"/>
<TextBlock Text="This is a test"/>
<TextBlock Text="This is a test"/>
<TextBlock Text="This is a test"/>
<TextBlock Text="This is a test"/>
<TextBlock Text="This is a test"/>
<TextBlock Text="This is a test"/>
<TextBlock Text="This is a test"/>
<TextBlock Text="This is a test"/>
<TextBlock Text="This is a test"/>
<TextBlock Text="This is a …Run Code Online (Sandbox Code Playgroud) 我可以找到关于Func <>和Action <>的所有示例都很简单,如下所示,您可以看到它们在技术上如何工作,但我希望看到它们用于解决以前无法解决的问题的示例中只有在一个更复杂的方式,即我知道他们是如何工作的,我可以看到他们是可以解决简洁,功能强大,所以我想了解他们在更大的意义上他们解决什么样的问题,我怎么可能会在使用它们应用程序设计.
您以什么方式(模式)使用Func <>和Action <>来解决实际问题?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace TestFunc8282
{
class Program
{
static void Main(string[] args)
{
//func with delegate
Func<string, string> convert = delegate(string s)
{
return s.ToUpper();
};
//func with lambda
Func<string, string> convert2 = s => s.Substring(3, 10);
//action
Action<int,string> recordIt = (i,title) =>
{
Console.WriteLine("--- {0}:",title);
Console.WriteLine("Adding five to {0}:", i);
Console.WriteLine(i + 5);
};
Console.WriteLine(convert("This is the first test.")); …Run Code Online (Sandbox Code Playgroud) 在Visual Studio 编辑器中,当您将滚动条向下拉到文件的底部时,您看到的只是一个空白页,因为文本已向上滚过文本编辑器窗口的顶部.这使得滚动到底部很困难,因为您不能一直快速拉动滚动条,但必须小心地定位光标,这样您仍然可以看到您的代码.
我怎么能这样做,就像在NotePad中,当我将滚动条向下拉到文件的底部时,我看到文件的底部?
下面的示例使用我从代码中获取的BackupDirectories列表填充ItemsControl.
如何更改此设置以便从app.config文件中获取相同的信息?
XAML:
<Window x:Class="TestReadMultipler2343.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="300" Width="300">
<Grid Margin="10">
<Grid.RowDefinitions>
<RowDefinition Height="30"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="120"/>
<ColumnDefinition Width="160"/>
</Grid.ColumnDefinitions>
<TextBlock
Grid.Row="0"
Grid.Column="0"
Text="Title:"/>
<TextBlock
Grid.Row="0"
Grid.Column="1"
Text="{Binding Title}"/>
<TextBlock
Grid.Row="1"
Grid.Column="0"
Text="Backup Directories:"/>
<ItemsControl
Grid.Row="1"
Grid.Column="1"
ItemsSource="{Binding BackupDirectories}"/>
</Grid>
</Window>
Run Code Online (Sandbox Code Playgroud)
后台代码:
using System.Collections.Generic;
using System.Windows;
using System.Configuration;
using System.ComponentModel;
namespace TestReadMultipler2343
{
public partial class Window1 : Window, INotifyPropertyChanged
{
#region ViewModelProperty: Title
private string _title;
public string Title
{
get …Run Code Online (Sandbox Code Playgroud) wpf ×5
xaml ×4
c# ×3
scrollviewer ×2
action ×1
app-config ×1
delegates ×1
editor ×1
fadein ×1
func ×1
gridview ×1
itemscontrol ×1
jquery ×1
listbox ×1
listview ×1
stackpanel ×1
vi ×1
vim ×1