下面的示例使用我从代码中获取的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) 当我在VirtualBox机器上安装Windows XP时,我将硬盘驱动器设置为仅10 GB,并假设它会扩大(就像我记忆中的VMWare中的硬盘驱动器一样,这不是真的吗?).
在任何情况下,我都试图在这个Virtual Box XP映像上安装Visual Studio 2010测试版,但磁盘空间已用完.
谷歌搜索答案,我发现这样复杂的教程,告诉你如何"在几个小时内 " 增加VirtualBox硬盘的大小.
但我无法想象这两者都难以:
如何在安装了XP的VirtualBox机器上轻松添加存储空间?
我正在使用LINQPad在我正在构建的应用程序中创建LINQ查询.
我注意到在下载的LINQ in Action示例中,例如示例4.04,intellisense显示了一个类"Books",但我在LINQPad工具中看不到任何引用或" using "语句,这里是示例:
List<Book> books = new List<Book>() {
new Book { Title="LINQ in Action" },
new Book { Title="LINQ for Fun" },
new Book { Title="Extreme LINQ" } };
var titles =
books
.Where(book => book.Title.Contains("Action"))
.Select(book => book.Title);
titles.Dump();
Run Code Online (Sandbox Code Playgroud)
在"LinqBooks.Common中,Business Objects,Book.linq "是类似乎定义的地方:
public class Book
{
public IEnumerable<Author> Authors {get; set;}
public String Isbn {get; set;}
public String Notes {get; set;}
public Int32 PageCount {get; set;}
public Decimal Price {get; …Run Code Online (Sandbox Code Playgroud) 我在WPF应用程序中创建了一个App.config文件:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appsettings>
<add key="xmlDataDirectory" value="c:\testdata"/>
</appsettings>
</configuration>
Run Code Online (Sandbox Code Playgroud)
然后我尝试用这个读取值:
string xmlDataDirectory = ConfigurationSettings.AppSettings.Get("xmlDataDirectory");
Run Code Online (Sandbox Code Playgroud)
但它说这已经过时了,我应该使用我找不到的ConfigurationManager,甚至在类视图中搜索.
有谁知道如何在WPF中使用这样的配置文件?
我使用Height ="*"来表示最后一行的高度应该填充到网格的底部.
但"10*"是什么意思?
<Grid Name="mainGrid">
<Grid.RowDefinitions>
<RowDefinition Height="100" />
<RowDefinition Height="40" />
<RowDefinition Height="10*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="200" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
</Grid>
Run Code Online (Sandbox Code Playgroud) 在HTML/CSS中,您可以定义可应用于许多类型元素的样式,例如:
.highlight {
color:red;
}
Run Code Online (Sandbox Code Playgroud)
可以应用于P和DIV,例如:
<p class="highlight">this will be highlighted</p>
<div class="highlight">this will also be highlighted</div>
Run Code Online (Sandbox Code Playgroud)
但在XAML中,您似乎必须为样式定义TargetType,否则会出现错误:
<Style x:Key="formRowLabel" TargetType="TextBlock">
Run Code Online (Sandbox Code Playgroud)
有没有办法允许XAML样式应用于多个元素,甚至像CSS一样让它保持打开状态?
当我从本文运行以下Northwind WPF Toolkit Datagrid代码时,我得到了一个数据网格,但是没有滚动条,因此用户只能看到部分数据网格.我使用的是2009年3月的最新版本.
我需要指定什么才能使WPF Datagrid具有滚动条?
我尝试将数据网格放在ScrollViewer中,但这没有帮助.
XAML:
<Window x:Class="TestDataGrid566.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:toolkit="http://schemas.microsoft.com/wpf/2008/toolkit"
Title="Window1" Height="600" Width="800">
<StackPanel>
<toolkit:DataGrid x:Name="TheDataGrid" AutoGenerateColumns="True"/>
</StackPanel>
</Window>
Run Code Online (Sandbox Code Playgroud)
后台代码:
using System.Linq;
using System.Windows;
using TestDataGrid566.Model;
namespace TestDataGrid566
{
public partial class Window1 : Window
{
public Window1()
{
InitializeComponent();
NorthwindDataContext db = new NorthwindDataContext();
var customers = from c in db.Customers
select c;
TheDataGrid.ItemsSource = customers;
}
}
}
Run Code Online (Sandbox Code Playgroud) 在Visual Studio 2008中,我可以在解决方案资源管理器中看到所有项目文件,这些文件存在于实际的文件中.
但是,如果我将文件添加到该目录(比如说,App_Data文件夹中的test.sqlite文件,或者说是其他程序创建的图像),那么这些文件就不会出现在我的解决方案资源管理器中,即使我点击了刷新按钮.
如何在其解决方案资源管理器中显示由其他应用程序创建的文件?
(到目前为止,我必须在其他地方创建它们,然后将它们复制并粘贴到解决方案资源管理器本身,但必须有一个更简单的方法).
这个"假解决方案视图"是否有优势,即我可以在我的App_Data目录中有一个文件"test.sqlite",但在我的解决方案中,它可能出现在我的根目录中.来自Eclipse WYSIWYG解决方案资源管理器的思维模式,我没有看到有关目录中实际文件的额外虚拟元信息的优势.有没有办法从这个比喻中获得优势?
我经常使用这个代码模式:
while(true) {
//do something
if(<some condition>) {
break;
}
}
Run Code Online (Sandbox Code Playgroud)
另一位程序员告诉我,这是不好的做法,我应该用更标准的替换它:
while(!<some condition>) {
//do something
}
Run Code Online (Sandbox Code Playgroud)
他的理由是你可以"轻易地忘记休息"并拥有无限循环.我告诉他,在第二个例子中你可以很容易地放入一个永远不会返回真实的条件,因此很容易有一个无限循环,所以两者都是同样有效的做法.
此外,我经常更喜欢前者,因为当你有多个断点时,即当多个条件退出循环时,它使代码更容易阅读.
任何人都可以通过为一方或另一方添加证据来丰富这一论点吗?
在Visual Studio中,我可以输入例如
对于 TAB TAB
并弹出一个代码片段.
是否有私有,公共等方法的内置代码片段?
wpf ×5
c# ×3
.net ×2
xaml ×2
app-config ×1
datagrid ×1
grid ×1
hard-drive ×1
itemscontrol ×1
linq ×1
linqpad ×1
readability ×1
scroll ×1
storage ×1
styles ×1
virtualbox ×1
while-loop ×1