如何在下面的状态栏中找到TextBlock以对齐?
我告诉过它:
但是文字仍然不合情理地坐在左边.我还有什么要说的?
<Window x:Class="TestEvents124.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="300"
MaxWidth="700" Width="700"
>
<DockPanel HorizontalAlignment="Stretch" Margin="0,0,0,0" Width="Auto">
<StatusBar Width="Auto" Height="25" Background="#888" DockPanel.Dock="Bottom" HorizontalAlignment="Stretch">
<TextBlock
Width="Auto"
Height="Auto"
Foreground="#fff"
Text="This is the footer."
HorizontalAlignment="Right"
TextAlignment="Right"
/>
</StatusBar>
<GroupBox DockPanel.Dock="Top" Height="Auto" Header="Main Content">
<WrapPanel Width="Auto" Height="Auto">
<TextBlock Width="Auto" Height="Auto" TextWrapping="Wrap" Padding="10">
This is an example of the content, it will be swapped out here.
</TextBlock>
</WrapPanel>
</GroupBox>
</DockPanel>
</Window>
Run Code Online (Sandbox Code Playgroud) 在WPF中定义DataContext似乎有两种主要方式:
App.xaml.cs(取自WPF MVVM Toolkit模板):
public partial class App : Application
{
private void OnStartup(object sender, StartupEventArgs e)
{
// Create the ViewModel and expose it using the View's DataContext
MainView mainView = new MainView();
MainViewModel mainViewModel = new MainViewModel();
mainViewModel.LoadCustomers("c:\\testdata2\\Customers.xml");
mainView.DataContext = mainViewModel;
mainView.Show();
}
}
Run Code Online (Sandbox Code Playgroud)
Window1.xaml:
<DockPanel>
<StackPanel
HorizontalAlignment="Left"
DockPanel.Dock="Top"
Orientation="Horizontal">
<StackPanel.DataContext>
<local:CustomerViewModel />
</StackPanel.DataContext>
<TextBlock Text="{Binding Path=FirstName}" />
<TextBlock Text=" " />
<TextBlock Text="{Binding Path=LastName}" />
</StackPanel>
<StackPanel
HorizontalAlignment="Left"
VerticalAlignment="top" …Run Code Online (Sandbox Code Playgroud) 在630 x 400窗口中,我正在加载XAML元素:
问题是,当我设置UserControl的背景时,颜色只会下降到内容.我希望UserControl的背景当然涵盖整个UserControl.我试过了:
但颜色仍然拒绝下降.我不想设置固定宽度,因为用户可以增加应用程序的大小.
如何获取UserControl的背景颜色以填充UserControl的整个区域而不仅仅是其内容的区域?
PageItemOptionsView.xaml:
<UserControl x:Class="TestMenu234.Views.PageItemOptionsView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
VerticalContentAlignment="Stretch"
VerticalAlignment="Stretch"
Background="#ddd">
<StackPanel Margin="10">
<TextBlock Text="This is the options area."/>
<Button Content="Click to go to the Manage Customers page."
Width="200"/>
</StackPanel>
</UserControl>
Run Code Online (Sandbox Code Playgroud)
MainView.xaml:
<Window x:Class="TestMenu234.Views.MainView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:c="clr-namespace:TestMenu234.Commands"
xmlns:vm="clr-namespace:TestMenu234.ViewModels"
xmlns:v="clr-namespace:TestMenu234.Views"
Title="Main Window" Height="400" Width="630" MinWidth="630">
Run Code Online (Sandbox Code Playgroud)
...
<DockPanel LastChildFill="False">
<Menu DockPanel.Dock="Top">
<MenuItem
Header="Pages" ItemsSource="{Binding AllPageItemViewModels}"
ItemTemplate="{StaticResource CodeGenerationMenuTemplate}"/> …Run Code Online (Sandbox Code Playgroud) 在我的演示者中,我有这个属性:
public List<string> PropertyNames { get; set; }
Run Code Online (Sandbox Code Playgroud)
我想用ItemsControl/DataTemplate列出名称,如下所示:
<ItemsControl ItemsSource="{Binding PropertyNames}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Value}"/>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
Run Code Online (Sandbox Code Playgroud)
由于通用列表没有命名属性,如何在Binding语句中引用该值?
我有一个27 x 27像素的图像,我在WPF中显示,但它显示大于窗口的大小.
如何让它显示其实际尺寸?
替代文字http://www.deviantsart.com/upload/m20dk6.png
XAML:
<Window x:Class="TestImage23434.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">
<StackPanel x:Name="MainStackPanel"/>
</Window>
Run Code Online (Sandbox Code Playgroud)
代码背后:
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media.Imaging;
using System;
namespace TestImage23434
{
public partial class Window1 : Window
{
public Window1()
{
InitializeComponent();
TextBlock tb = new TextBlock();
tb.Text = "above image ";
MainStackPanel.Children.Add(tb);
Image img = new Image();
img.Source = new BitmapImage(new Uri(@"C:\test\circle.png"));
img.HorizontalAlignment = HorizontalAlignment.Left;
img.VerticalAlignment = VerticalAlignment.Top;
MainStackPanel.HorizontalAlignment = HorizontalAlignment.Left;
MainStackPanel.VerticalAlignment = VerticalAlignment.Top;
MainStackPanel.Children.Add(img);
TextBlock tb2 …Run Code Online (Sandbox Code Playgroud) 这适用于LINQ-to-SQL:
var customersTest = from c in db.Customers
select new
{
Id = c.Id,
Addresses = from a in db.Addresses where c.Id.ToString() ==
a.ReferenzId select a
};
foreach (var item in customersTest)
{
Console.WriteLine(item.Id);
}
Run Code Online (Sandbox Code Playgroud)
但实体框架中的类似示例会收到一条错误消息,表示它无法"将其转换为SQL",这是德语中的原始错误消息:
"'LINQ to Entities'erkennt die Methode'System.String ToString()'nicht,und diese Methode kann nicht in einenSpeicherausdruckübersetztwerden."
翻译:
"'LINQ to Entities'无法识别Method'System.String ToString()',此方法无法转换为内存表达式.
任何人都可以阐明我们如何在Entity Framework中使用这种语句或解释为什么会出现这个错误?
在下面的示例中,我能够在继承的类中创建一个虚方法,然后在继承类中覆盖它.Show()
我想用受保护的类变量做同样的事情,但我得到错误: prefix
修饰符'virtual'对此项无效
但由于我无法在我的类中将此变量定义为虚拟/覆盖,因此我收到编译器警告:
TestOverride234355.SecondaryTransaction.prefix'隐藏继承的成员'TestOverride234355.Transaction.prefix'.如果要隐藏,请使用new关键字.
幸运的是,当我添加new关键字时,一切正常,这是好的,因为我得到了相同的功能,但这提出了两个问题:
为什么我可以使用虚拟/覆盖方法而不是受保护的类变量?
虚拟/覆盖方法与隐藏它与新方法之间的实际区别是什么,因为至少在这个例子中它们提供相同的功能?
码:
using System;
namespace TestOverride234355
{
public class Program
{
static void Main(string[] args)
{
Transaction st1 = new Transaction { Name = "name1", State = "state1" };
SecondaryTransaction st2 =
new SecondaryTransaction { Name = "name1", State = "state1" };
Console.WriteLine(st1.Show());
Console.WriteLine(st2.Show());
Console.ReadLine();
}
}
public class …Run Code Online (Sandbox Code Playgroud) 如何定义一个小数组而不显式地每个小数组?
//decimal[] prices = { 39.99, 29.99, 29.99, 19.99, 49.99 }; //can't convert double to decimal
//var prices = { 39.99, 29.99, 29.99, 19.99, 49.99 }; //can't initialize...
decimal[] prices = { (decimal)39.99, (decimal)29.99, (decimal)29.99, (decimal)19.99, (decimal)49.99 };
Run Code Online (Sandbox Code Playgroud) 我有一个regionContent面板,我添加到我的视口.
如何用新内容替换其内容?
...
var regionContent = new Ext.Panel({
id: 'contentArea',
region: 'center',
padding:'10',
autoScroll: true,
html: 'this is the original content'
});
var viewport = new Ext.Viewport({
layout: 'border',
items: [ regionMenu, regionContent ]
});
var newPanel = new Ext.Panel({
region: 'east',
title: 'Info Panel',
width: 300,
html: 'this is a panel that is added'
});
// regionContent.update(newPanel); //renders as javascript code ???
// regionContent.remove(...) //how do I remove ALL CONTENT, I will not know what is in …Run Code Online (Sandbox Code Playgroud) 在下面的示例代码中,我收到此错误:
Element TestSerializeDictionary123.Customer.CustomProperties vom Typ System.Collections.Generic.Dictionary`2 [[System.String,mscorlib,Version = 2.0.0.0,Culture = neutral,PublicKeyToken = b77a5c561934e089],[System.Object,mscorlib,Version = 2.0 .0.0,Culture = neutral,PublicKeyToken = b77a5c561934e089]]无法序列化,因为它实现了IDictionary.
当我取出Dictionary属性时,它工作正常.
如何使用字典属性序列化此Customer对象?或者我可以使用哪种替换类型的Dictionary可序列化?
using System;
using System.Collections.Generic;
using System.Xml.Serialization;
using System.IO;
using System.Xml;
using System.Text;
namespace TestSerializeDictionary123
{
public class Program
{
static void Main(string[] args)
{
List<Customer> customers = Customer.GetCustomers();
Console.WriteLine("--- Serializing ------------------");
foreach (var customer in customers)
{
Console.WriteLine("Serializing " + customer.GetFullName() + "...");
string xml = XmlHelpers.SerializeObject<Customer>(customer);
Console.WriteLine(xml);
Console.WriteLine("Deserializing ...");
Customer customer2 = XmlHelpers.DeserializeObject<Customer>(xml); …Run Code Online (Sandbox Code Playgroud) c# ×6
xaml ×5
wpf ×4
arrays ×1
autosize ×1
casting ×1
data-binding ×1
datacontext ×1
decimal ×1
dictionary ×1
extjs ×1
image ×1
itemscontrol ×1
linq ×1
linq-to-sql ×1
new-operator ×1
oop ×1
overriding ×1
virtual ×1