小编Ter*_*rco的帖子

wpf控制宽度绑定

我有两个内容边框,第二个边框宽度根据内容而变化,我正在尝试将第一个边框绑定到第二个边框宽度,但它不起作用,我不确定我缺少什么.有人可以给我一些方向吗?以下是我目前正在尝试的一个例子.

<Border x:Name="border1" Width="{Binding Path=Width, ElementName=border2}">
    ... 
</Border>

<Border x:Name="border2">
    ...
</Border>
Run Code Online (Sandbox Code Playgroud)

wpf binding width

28
推荐指数
1
解决办法
3万
查看次数

在代码中设置ColumnDefinitions

我想知道是否有一种方法可以在代码中将ColumnDefinition Width设置为*,就像在xaml文件中一样.当尝试在代码中设置GridLength时,只有Auto有一个选项.

<ColumnDefinition Width="*"/>
Run Code Online (Sandbox Code Playgroud)

谢谢你的帮助.

c# wpf grid width

19
推荐指数
1
解决办法
1万
查看次数

log4net MemoryAppender无法正常工作

我正在使用log4net登录我的应用程序.我的FileAppender工作正常,但我遇到MemoryAppender问题.

这是我的配置文件.

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <configSections>
        <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
    </configSections>
<log4net>
<appender name="LogFileAppender" type="log4net.Appender.FileAppender">
  <param name="File" value="Envision.log" />
  <param name="AppendToFile" value="true" />
  <layout type="log4net.Layout.PatternLayout">
    <param name="Header" value="" />
    <param name="Footer" value="" />
    <param name="ConversionPattern" value="%d [%t] %-5p %m%n" />
  </layout>
</appender>
<appender name="MemoryAppender" type="log4net.Appender.MemoryAppender">

</appender>
<root>
  <level value="ALL" />
  <appender-ref ref="LogFileAppender" />
  <appender-ref ref="MemoryAppender" />
</root>
</log4net>
</configuration>
Run Code Online (Sandbox Code Playgroud)

我使用此代码来设置配置文件.

FileInfo file = new FileInfo(configPath);
log4net.Config.XmlConfigurator.Configure(file);
file = null;
Run Code Online (Sandbox Code Playgroud)

就像我说的,FileAppender效果很好.但我似乎无法得到任何事件.我试过用这样的东西来获取MemoryAppender.

Hierarchy hierarchy = LogManager.GetRepository() as Hierarchy;
MemoryAppender …
Run Code Online (Sandbox Code Playgroud)

log4net appender

7
推荐指数
2
解决办法
6895
查看次数

如何知道这是循环的最后一次迭代?

有没有一种奇特的方法可以知道你在List中的最后一个循环中而不使用计数器

List<string> myList = new List<string>() {"are", "we", "there", "yet"};

foreach(string myString in myList) {
    // Is there a fancy way to find out here if this is the last time through?
}
Run Code Online (Sandbox Code Playgroud)

c# generics list

7
推荐指数
1
解决办法
4655
查看次数

用模板绑定设置​​边框背景

Value ="{TemplateBinding HeaderColor}"我创建了自己的控件,我想知道是否可以将Border.Background绑定到模板属性.目前我正在使用如下的StaticResource设置它:

<Color x:Key="ControlMouseOverColor">green</Color>

<ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(Border.Background).(GradientBrush.GradientStops)[1].(GradientStop.Color)" Storyboard.TargetName="headerLayout">
    <EasingColorKeyFrame KeyTime="0:0:6" Value="{StaticResource ControlMouseOverColor}" />
</ColorAnimationUsingKeyFrames>
Run Code Online (Sandbox Code Playgroud)

我希望它是我控制的属性,并能够将其设置为模板绑定

<ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(Border.Background).(GradientBrush.GradientStops)[1].(GradientStop.Color)" Storyboard.TargetName="headerLayout">
    <EasingColorKeyFrame KeyTime="0:0:6" Value="{TemplateBinding HeaderColor}" />
</ColorAnimationUsingKeyFrames>
Run Code Online (Sandbox Code Playgroud)

MainPage.xaml中

<ctrl:Selection Grid.Column="0" HeaderColor="Red" HeaderText="Header Text" />
Run Code Online (Sandbox Code Playgroud)

我的课:

public static readonly DependencyProperty HeaderColorProperty =
        DependencyProperty.Register("HeaderColor", typeof(System.Windows.Media.Color), typeof(Selection), new PropertyMetadata(System.Windows.Media.Colors.Red));

public  System.Windows.Media.Color HeaderColor {
    get { return (System.Windows.Media.Color)GetValue(HeaderColorProperty); }
    set { SetValue(HeaderColorProperty, value); }
}
Run Code Online (Sandbox Code Playgroud)

如果我能够这样做,第二个选项不起作用?我没有收到错误,它只是没有改变我设置的颜色.

AngelWPF留下的评论要求更多代码,粘贴在下面,我正处于学习创建控件的开始阶段,想要注意,因为有很多我还没有,一次一件:)

generic.xaml

<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:controls="clr-namespace:SelectionControl.Library"
xmlns:ctrl="clr-namespace:SelectionControl.Library;assembly=SelectionControl">

<LinearGradientBrush x:Key="HeaderBackground" EndPoint="0.5,1" StartPoint="0.5,0">
    <GradientStop Color="Black" Offset="0" />
    <GradientStop Color="Gray" Offset="1" />
</LinearGradientBrush>

<Color …
Run Code Online (Sandbox Code Playgroud)

silverlight background colors templatebinding

5
推荐指数
1
解决办法
3445
查看次数

使用System.Data.Linq.Mapping并在sqlite db中自动递增主键时出错

我正在使用SQLiteSystem.Data.Linq.Mapping.id AUTOINCREMENT使用linq mapping属性时,我遇到了该字段的问题IsDbGenerated = true.

创建表的语法.我已经尝试了这个/没有AUTOINCREMENT

CREATE TABLE [TestTable] ([id] INTEGER  NOT NULL PRIMARY KEY AUTOINCREMENT,[title] TEXT  NULL)
Run Code Online (Sandbox Code Playgroud)

我的TABLE类:

[Table(Name = "TestTable")]
public class TestTable
{
    [Column(IsPrimaryKey = true, IsDbGenerated =true)]
    public int id { get; set; }

    [Column]
    public string title { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

这是我如何称呼它.当它提交我得到一个错误,我将粘贴此示例下面的错误.需要注意的一件事是,如果我拿出IsDbGenerated =true上面的内容并id手动输入它确实插入正常,但我喜欢它,AUTOINCREMENT并且由于某种原因,它IsDbGenerated=true正在杀死插入物.寻求一些指导.

static void Main(string[] args)
{
    string connectionString = @"DbLinqProvider=Sqlite;Data Source = c:\pathToDB\test.s3db";
    SQLiteConnection connection …
Run Code Online (Sandbox Code Playgroud)

c# sql linq sqlite system.data.sqlite

5
推荐指数
1
解决办法
2550
查看次数

如何绑定图像源?

从一些例子来看,我认为我这样做是正确的,但它没有用,所以我想在这里查看.我绑定了我的图像源,但图像不在那里.如果我拿走我的绑定并将Image源设置为下面方法中使用的路径,它可以正常工作.

public Image myImage = new Image();

public void someMethod() {
    BitmapImage biSource = new BitmapImage();
    biSource.BeginInit();
    biSource.CacheOption = BitmapCacheOption.OnLoad;
    biSource.CreateOptions = BitmapCreateOptions.IgnoreImageCache;
    biSource.UriSource = new Uri(@"C:\Images\testimage.jpg");
    biSource.DecodePixelWidth = 150;
    biSource.EndInit();

    myImage.Source = biSource;
}

xaml code
<Image Source="{Binding Path=myImage}" Width="150" Height="150" />
Run Code Online (Sandbox Code Playgroud)

wpf binding image

3
推荐指数
2
解决办法
4355
查看次数

绑定按钮IsEnabled到StackPanel有孩子

我想知道我是否可以将我的Button isEnabled绑定到我的StackPanel Children(有孩子).如果stackpanel有子项,那么我的按钮被启用,没有孩子我的按钮被禁用.目前我只是在代码中处理这个,但我开始想知道这是否是我可以绑定的东西.谢谢你的任何想法......

wpf binding button stackpanel isenabled

3
推荐指数
1
解决办法
1761
查看次数

将LinearGradientBrush而不是纯色设置为VisualState中的storyboard.targetProperty

我想知道如何将Storyboard.TargetProperty设置为LinearGradientBrush而不是纯色.我是VisualStates的新手,所以如果我的问题没有提供足够的信息,请告诉我.大多数情况下,我只想设置渐变而不是纯色,无法弄清楚如何.谢谢你的帮助.我的工作是在http://msdn.microsoft.com/en-us/library/ms753328.aspx上找到的一个例子.

 <VisualState x:Name="Disabled">
    <Storyboard>
        <ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(Panel.Background).
                  (GradientBrush.GradientStops)[1].(GradientStop.Color)"
                                            Storyboard.TargetName="Border">
                <EasingColorKeyFrame KeyTime="0"
                                     Value="{StaticResource DisabledControlDarkColor}" />
              </ColorAnimationUsingKeyFrames>
              <ColorAnimationUsingKeyFrames
                  Storyboard.TargetProperty="(TextBlock.Foreground).(SolidColorBrush.Color)"
                                            Storyboard.TargetName="Border">
                <EasingColorKeyFrame KeyTime="0"
                                     Value="{StaticResource DisabledForegroundColor}" />
              </ColorAnimationUsingKeyFrames>
              <ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(Border.BorderBrush).
                  (GradientBrush.GradientStops)[1].(GradientStop.Color)"
                                            Storyboard.TargetName="Border">
                <EasingColorKeyFrame KeyTime="0"
                                     Value="{StaticResource DisabledBorderDarkColor}" />
              </ColorAnimationUsingKeyFrames>
            </Storyboard>
          </VisualState>
Run Code Online (Sandbox Code Playgroud)

wpf storyboard lineargradientbrush

3
推荐指数
1
解决办法
5721
查看次数