我是WPF的新手。我理解定义全局应用程序资源的概念,我可以在整个应用程序中参考这些资源。我看到我可以在应用程序资源下定义一个文本块,但似乎无法看到如何在窗口中引用它。
在Application.Resources中,我有以下代码:
<?php
echo "<pre>";
print_r($_POST);
echo "</pre>";
if(isset($_POST['calculate'])) {
// creating an array
$error = array();
if((isset($_POST['buyer']) && is_numeric($_POST['buyer'])) || (isset($_POST['seller']) && is_numeric($_POST['seller']))) {
// setting index
$error ['buyer'] ['0'] = "the byer or seller is not numeric";
$error ['seller'] ['0'] = "the seller is not numericc";
} elseif((isset($_POST['buyer']) && !empty($_POST['buyer'])) || (isset($_POST['seller']) && !empty($_POST['seller']))) {
$buyer = $_POST['buyer'];
$seller = $_POST['seller'];
// here the error comes
} else {
$error ['buyer'] ['1'] = "please input the buyer name";
$error ['seller'] ['1'] = "please input the seller name";
}
if(empty($_POST['product'])) {
$error ['product'] ['0'] = "Please select a Product";
}
// so finally print the array shows the index which i didn't want to start from 1
echo "<pre>";
print_r($error);
echo "</pre>";
// the buyer associative array starts indexing from1
}
?>
如何在任何给定的窗口中构建一个新的文本块,该窗口返回&#34; ABC_Copyright&#34;申请资源?
提前致谢。
答案 0 :(得分:1)
我们将其定义为一种风格;
<Style x:Key="ABC_Copyright" TargetType="TextBlock">
<Setter Property="Background" Value="Beige"/>
<Setter Property="Text" Value="Copyright 2016 ABC Company"/>
</Style>
然后我们在任何我们需要的实例中使用它;
<TextBlock Style="{StaticResource ABC_Copyright}"/>
希望这会有所帮助,欢呼。
答案 1 :(得分:0)
创建您要存储的ResourceDictionary
,并将Resource Dictionary
名称作为ResourceDictionary
的来源App.xaml
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Your Resource Dictionary Name"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
现在ResourceDictionary
样式你的textbolck
可以从任何其他类似的地方访问,
<Style x:Key="TxtStyle" TargetType="{x:Type TextBlock}">
<Setter Property="Text" Value="Copyright 2016 ABC Company"/>
</Style>
现在将您的textblock
推荐给带样式的textblock
<TextBlock x:Key="ABC_Copyright" Background="Beige" Style="{StaticResource TxtStyle}"/>