我試圖運行this example但我遇到綁定問題。WPF綁定:靜態資源無法解析
設計凸顯了錯誤The resource "monthCollection" could not be resolved
如何使用Utility.MonthCollection作爲本地資源?
XAML部分:
<Window x:Class="FaceReport.WindowMain"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Rapor" Height="402" Width="600" WindowState="Normal">
<Grid Name="gridMain" x:Uid="uidGridMain">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<ComboBox SelectedIndex="0"
DisplayMemberPath="Value" SelectedValuePath="Key" Margin="132,9,200,0"
Grid.Row="3" Height="24" VerticalAlignment="Top" Name="cbBind"
ItemsSource="{Binding Source={StaticResource Utility.ReportForCollection},
Path=Utility.ReportForCollection}"
/>
</Grid>
</Window>
C#部分:
namespace FaceReport
{
internal class Utility
{
public enum ReportFor
{
Choose,
All,
Group,
Person
}
private static Dictionary<ReportFor, string> _dictReportFor;
public static Dictionary<ReportFor, string> ReportForCollection
{
get
{
return _dictReportFor;
}
}
static Utility()
{
//initialize the collection with user friendly strings for each enum
_dictReportFor = new Dictionary<ReportFor, string>(){
{ReportFor.Choose, "Lütfen seçiniz..."},
{ReportFor.All, "Herkes"},
{ReportFor.Group, "Grup"},
{ReportFor.Person, "Şahıs"}};
}
}
/// <summary>
/// Application's main form
/// </summary>
public partial class WindowMain : Window
{
/// <summary>
/// Constructor
/// </summary>
public WindowMain()
{
InitializeComponent();
}
}
請發佈代碼的相關部分,而不是鏈接到外部網站或博客。 –