小编Mat*_* H.的帖子

无法覆盖由TargetType在单个特定控件上设置的全局WPF样式

我有一个样式应用于我在资源字典中定义的所有文本框.

<Style TargetType="TextBlock">
        <Setter Property="TextBlock.FontSize" Value="{Binding Source={StaticResource ApplicationUserSettings}, Path=fontSize, Mode=OneWay}" />
        <Setter Property="TextBlock.TextWrapping" Value="Wrap" />
        <Setter Property="TextBlock.VerticalAlignment" Value="Center"/>
        <Setter Property="Background" Value="Transparent"/>
        <Setter Property="TextBox.FontFamily" Value="{Binding Source={StaticResource ApplicationUserSettings}, Path=fontName, Mode=OneWay}"/>
    </Style>\
Run Code Online (Sandbox Code Playgroud)

fontsize和fontstyle属性绑定到实现iNotifyPropertyChanged的特殊用户设置类,它允许更改字体大小和fontfamily以在我的应用程序中立即传播.

但是,在我创建的UserControl中(具有讽刺意味的是,允许用户自定义字体设置的屏幕),我希望字体大小和fontfamily保持静态.无论我尝试什么,我的全局字体设置都会覆盖我在用户控件中设置的内容:

<UserControl x:Class="ctlUserSettings"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:R2D2" Height="400" Width="600">

<Grid>

    <Grid.Resources>
        <Style x:Key="tbxStyle" TargetType="TextBox">
            <Style.Setters>
                <Setter Property="FontSize" Value="14"/>
                <Setter Property="FontFamily" Value="Tahoma"/>
            </Style.Setters>
        </Style>
Run Code Online (Sandbox Code Playgroud)

......等......

         <StackPanel Margin="139,122.943,41,0" Orientation="Horizontal" Height="33" VerticalAlignment="Top">
            <TextBox Style="{x:Null}" FontSize="13" FontFamily="Tahoma" HorizontalAlignment="Left" MaxWidth="500" MinWidth="350" Name="txtReaderPath" Height="Auto" VerticalAlignment="Top" />
            <TextBox Style="{x:tbxStyle}" Margin="15,0,0,0" HorizontalAlignment="Left" Name="txtPath" Width="43" Height="23" VerticalAlignment="Top">(some text)</Button>
        </StackPanel>
Run Code Online (Sandbox Code Playgroud)

我尝试将Style设置为{x:Null},设置内联自定义字体大小,并在此控件的资源中设置样式.没有优先于我的资源字典中的样式. …

wpf user-controls styles font-size font-family

8
推荐指数
1
解决办法
4157
查看次数

iOS - 何时创建子ViewController与UIView子类?

也许这是一个愚蠢的问题,但我在iOS开发过程中多次遇到过这个问题.

有时候我会开发一个我想在多个屏幕上使用的视图组件,所以我决定将其子类化UIView并制作成可以在多个地方使用的东西.

然后,我开始添加功能.也许它需要响应一个NSNotification,或者它应该响应用户触摸.

在某一点上,我开始想知道我是否应该真正创建一个UIViewController子类,并将其作为子ViewController添加到我的UI中.

是否有任何共识在哪些界面之间划清界线UIView,以及何时创建完整UIViewController

uiviewcontroller uiview ios

8
推荐指数
2
解决办法
1410
查看次数

C#将UTC int转换为DateTime对象

我不知道为什么这么复杂!

我有一个传入long int UTC的插件.我需要将该数字转换DateTime为查询我的数据库(SQL Server).

我不知道为什么,但我从基本的谷歌搜索中找不到可行的答案.

(为了额外的功劳,我需要DateTime在一天结束时将我的返回信号转回UTC.)

不得不提出这样一个基本问题,这很令人尴尬!:)

.net c# sql-server utc

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

在JavaScript中使用setInterval而不使用内联的匿名函数

我想要实现的是,最初将加载数据,然后使用相同的功能每十分钟更新一次.

考虑以下代码:

var updateNamespace = (function() {
    var object = '#updates',
    load = 'loader';

    return {
        update: function() {
            $(object).addClass(load).load('update.php', function(reponse, status, xhr) {
                if (status == 'error') {
                    $(this).html('<li>Sorry but there was an error in loading the news &amp; updates.</li>');
                }
                $(this).removeClass(load);
            }); 
        }
    }
})();

setInterval(updateNamespace.update(), 600000);
Run Code Online (Sandbox Code Playgroud)

我收到此错误:

useless setInterval call (missing quotes around argument?)
Run Code Online (Sandbox Code Playgroud)

我怎样才能解决这个问题?

写这个或使用setInterval函数的更好,更优雅的方法是什么?

谢谢.

javascript

6
推荐指数
1
解决办法
3807
查看次数

如何对webkit matrix3d转换进行逆向工程

我有一个立方体元素在3d空间中旋转和翻译.

我想找出刚才的这个旋转Y部分变换在给定时间.这可能吗?

我有:

var cube = document.getElementById("cube");
var transform = getComputedStyle(cube).webkitTransform;

//the value of transform is:
// matrix3d(-1, 0, 0.00000000000000012246467991473532, 0, 
//           0, 1, 0, 0, 
//          -0.00000000000000012246467991473532, 0, -1, 0, 
//           0, 0, 0, 1)
Run Code Online (Sandbox Code Playgroud)

救命?:-)

css webkit matrix css3 css-transforms

6
推荐指数
1
解决办法
3198
查看次数

Objective-C阻止"保留周期"警告,不明白为什么

我已经看到了同样形式的其他几个问题,但我要么a)无法理解所提供的答案,要么b)看不出那些情况与我的相似.

我正在UIView上编写一个类别,以递归方式评估UIView的所有子视图,并返回通过测试的子视图数组.我已经注意到我的编译器警告发生在哪里:

-(NSArray*)subviewsPassingTest:(BOOL(^)(UIView *view, BOOL *stop))test {

   __block BOOL *stop = NO;

    NSArray*(^__block evaluateAndRecurse)(UIView*);
    evaluateAndRecurse = ^NSArray*(UIView *view) {
        NSMutableArray *myPassedChildren = [[NSMutableArray alloc] init];
        for (UIView *subview in [view subviews]) {
            BOOL passes = test(subview, stop);
            if (passes) [myPassedChildren addObject:subview];
            if (stop) return myPassedChildren;


            [myPassedChildren addObjectsFromArray:evaluateAndRecurse(subview)];
            // ^^^^ Compiler warning here ^^^^^
            // "Capturing 'evaluateAndRecurse' strongly in this block 
            // is likely to lead to a retrain cycle"
        }
        return myPassedChildren;
    };

    return evaluateAndRecurse(self);
}
Run Code Online (Sandbox Code Playgroud)

另外,当我__block在块的声明中不包含修饰符时,我得到bad_access失败(^__block …

objective-c objective-c-blocks

6
推荐指数
1
解决办法
670
查看次数

如何检索ItemsControl中项目的DataTemplate(和特定对象)?

我已经看到了一个非常类似的问题的解决方案,但它没有转化为我的.(即,这篇文章:http://blogs.msdn.com/wpfsdk/archive/2007/04/16/how-do-i-programmatically-interact-with-template-generated-elements-part-ii.aspx)

我的ItemsControl绑定到一个可观察的集合,可以动态添加项目.

当我将项目添加到observable集合时,模板化项目在我的itemscontrol中正确呈现,但我无法弄清楚如何访问它.我的可观察集合改变了代码,我正在尝试访问有关的信息.我正在使用自定义DataTemplateSelector根据集合中项目的数据返回3个不同的dataTemplates之一.

这是我的ItemsControl XAML的概述:

<ItemsControl Name="myItemsControl" ItemTemplateSelector="{StaticResource myTempSelector}">
    <ItemsControl.Template>
        <ControlTemplate TargetType="ItemsControl">
            <ItemsPresenter/>
        </ControlTemplate>
    </ItemsControl.Template>
    <ItemsControl.ItemsPanel>
        <ItemsPanelTemplate>
            <StackPanel></StackPanel>   
        </ItemsPanelTemplate>
    </ItemsControl.ItemsPanel>

    </ItemsControl>
Run Code Online (Sandbox Code Playgroud)

我见过的解决方案建议使用 ItemContainerGenerator.ContainerFromItem(xxx)

在这个例子中,他们总是在寻找有关ListBox或ComboBox(从ContentControl继承)的信息.但是,当我调用(在我的代码后面)时myItemsControl.ItemContainerGenerator.ContainerFromItem(xxx),我会收到一个ContentPresenter,而不是我期望的ContentControl.

然后,当我尝试访问此ContentPresenter的ContentTemplate时,我得到一个null对象异常.

我有一种预感,其余的麻烦从那里下来.

我想要做的就是从我新创建的控件中的datatemplate中找到一个文本框,并给它重点.

救命!:-)

.net wpf datatemplate itemscontrol

4
推荐指数
1
解决办法
1965
查看次数

XAML:请参阅普通XAML中的StaticResource?(没有标记扩展名)

我正在设置一系列文本框的验证规则.我宁愿不为每个TextBox创建一个新的自定义验证规则实例......

<Window.Resources>
  <my:IsIntegerRule x:Key="IsIntegerRule"/>
</Window.Resources>

...
...

<TextBox>
    <TextBox.Text>
      <Binding XPath="@num" UpdateSourceTrigger="PropertyChanged" Mode="TwoWay">
         <Binding.ValidationRules>

            <-- WHAT IS THE EQUIVALENT OF WRITING: {StaticResource IsIntegerRule} here -->

         </Binding.ValidationRules>
      </Binding>
     </TextBox.Text>
 </TextBox>
Run Code Online (Sandbox Code Playgroud)

有人可以帮忙吗?

vb.net data-binding validation wpf xaml

4
推荐指数
1
解决办法
3068
查看次数

为什么NSObject的"isMemberOfClass:class"在XCode的自动完成中指定__unsafe_unretained?

模糊的概述是我正在一个NSArray类别中编写一个方法,该方法将Class一个Array过滤到属于该类成员的元素.就像是:

@implementation NSArray(filter)
-(NSArray*)objectsOfClass:(Class)aClass {
   NSMutableArray *ret = [[NSMutableArray alloc] init];   
   for (id obj in self)
       if ([obj isMemberOfClass:aClass])
          [ret addObject:obj];

   return [NSArray arrayWithArray:ret];
}
@end
Run Code Online (Sandbox Code Playgroud)

Sooo,除此之外,我的问题.NSObject.h显示isMemberOfClass:具有以下签名:

 -(BOOL)isMemberOfClass:(Class)aClass;
Run Code Online (Sandbox Code Playgroud)

当我在XCode中键入此方法时,自动完成提示方法签名如下所示:

 [self isMemberOfClass:(__unsafe_unretained Class)]
Run Code Online (Sandbox Code Playgroud)

我的问题是:

1)为什么NSObject.h中的方法原型和XCode的自动完成之间存在差异?
2)在我自己的方法中(在这个问题的开头显示),我应该包含__unsafe_unretained修饰符吗?如果是这样,为什么?如果没有,为什么不呢?

谢谢!

xcode objective-c automatic-ref-counting

4
推荐指数
1
解决办法
712
查看次数

Swift 类型擦除尝试:“引用无效的关联类型”

我正在做一个虚构的练习来尝试实现一个类型擦除的容器。

import Foundation

protocol MoverType {
    func move()
}
extension MoverType {
    func move() { print("\(type(of: self)) is moving") }
}

class Slithering: MoverType {}
class Walking: MoverType {}
class Trotting: MoverType {}

protocol Animal {
    associatedtype Mover: MoverType
    var mover: Mover { get }
}

class Snake: Animal {
    let mover = Slithering()
}
class Dog: Animal {
    let mover = Trotting()
}
class Human: Animal {
    let mover = Walking()
}

class AnyAnimal: Animal {  // ERROR: Type …
Run Code Online (Sandbox Code Playgroud)

generics type-erasure swift swift-protocols

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