| 

.NET C# Java Javascript Exception

2
Hallo an alle!

Ich habe ein Problem mit meinem WPF Projekt. In meinem Formular habe ich ein Listview, welches Arbeitszeiten anzeigt. Wenn es einen Feiertag gibt, soll diese Zeile einen grauen Hintergrund bekommen. Beim Durchstöbern des www ist mir ein Beispiel in die Hand gefallen, welches ich umgesetzt habe, nur läßt sich mein Projekt nicht compilieren.

Hier die entsprechenden Codezeilen:

Ausschnitt aus dem XAML:
<Window x:Class="WorktimeTrackerReport.frmMain"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:wtr="clr-namespace:WorktimeTrackerReport.Helperclasses"
Title="WorktimeTracker - Verwaltung" Height="696.321" Width="929.955" Loaded="Window_Loaded" WindowStartupLocation="CenterScreen" ResizeMode="NoResize" Icon="Icons/timestamp.ico" Background="#FFFBF6F6">
<Window.Resources>
<wtr:ListViewItemStyleSelector x:Name="myStyleSelector" />
<Style TargetType="{x:Type TextBlock}"
x:Key="GridBlockStyle">
<Setter Property="VerticalAlignment" Value="Center" />
<Setter Property="Visibility"
Value="{Binding Path=IsSelected,
RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ListViewItem}},
ConverterParameter=False}" />
</Style>
</Window.Resources>

......

<ListView x:Name="lvOutput" HorizontalAlignment="Left" Height="174"
VerticalAlignment="Top" Width="883" SelectionChanged="lvOutput_SelectionChanged"
Margin="0,0,-2,0" ItemContainerStyleSelector="{DynamicResource myStyleSelector}" >
<ListView.View>
<GridView x:Name="lvDataGrid" AllowsColumnReorder="False">
<GridViewColumn>
<GridViewColumnHeader Click="lvOutputSort_Click" Tag="Lastname" Content="Nachname" />
<GridViewColumn.CellTemplate>
<DataTemplate>
<Grid>
<TextBlock Text="{Binding Path=Lastname}" Style="{StaticResource GridBlockStyle}" />
</Grid>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>

........


Der C# Code:
namespace WorktimeTrackerReport.Helperclasses {
public class ListViewItemStyleSelector : StyleSelector {
public override Style SelectStyle(object item, DependencyObject container) {
Style st = new Style();
st.TargetType = typeof(ListViewItem);
Setter backGroundSetter = new Setter();
backGroundSetter.Property = ListViewItem.BackgroundProperty;
ListView listView = ItemsControl.ItemsControlFromItemContainer(container) as ListView;

clsLvItemHelperOutput objItem = (clsLvItemHelperOutput)listView.ItemContainerGenerator.ItemFromContainer(container);
if (objItem.IsPublicHoliday) {
backGroundSetter.Value = Brushes.LightGray;
}
else {
backGroundSetter.Value = Brushes.Transparent;
}
st.Setters.Add(backGroundSetter);
return st;
}
}
}


Er meckert mir diese Zeile an:
<wtr:ListViewItemStyleSelector x:Name="myStyleSelector" />


Und zwar mit dieser Fehlermeldung:

The name "ListViewItemStyleSelector" does not exist in the namespace "clr-namespace:WorktimeTrackerReport.Helperclasses".

Wo kommt dieser Fehler her und wie kann ich das korrigieren? Meine Klasse ist Public und den Namespace habe ich auch im XAML angegeben. Ich verstehe das nicht!!
01.04.2015
tschroeer 35 1 4
3 Antworten
0
Noch eine Ergänzung:

Die Items sind an eine ObservableCollection gebunden.

private ObservableCollection<clsLvItemHelperOutput> myAZCollection = new ObservableCollection<clsLvItemHelperOutput>();
public ObservableCollection<clsLvItemHelperOutput> objAZCollection {
get { return myAZCollection; }
}


Und meine Hilfsklasse sieht so aus:
public class clsLvItemHelperOutput : DependencyObject {
public static readonly DependencyProperty RowIDProperty = DependencyProperty.Register("RowID", typeof(string), typeof(clsLvItemHelperOutput), new UIPropertyMetadata(null));
public string RowID {
get { return (string)GetValue(RowIDProperty); }
set { SetValue(RowIDProperty, value); }
}

public static readonly DependencyProperty UserIDProperty = DependencyProperty.Register("UserID", typeof(string), typeof(clsLvItemHelperOutput), new UIPropertyMetadata(null));
public string UserID {
get { return (string)GetValue(UserIDProperty); }
set { SetValue(UserIDProperty, value); }
}

public static readonly DependencyProperty LastnameProperty = DependencyProperty.Register("Lastname", typeof(string), typeof(clsLvItemHelperOutput), new UIPropertyMetadata(null));
public string Lastname {
get { return (string)GetValue(LastnameProperty); }
set { SetValue(LastnameProperty, value); }
}

public static readonly DependencyProperty FirstnameProperty = DependencyProperty.Register("Firstname", typeof(string), typeof(clsLvItemHelperOutput), new UIPropertyMetadata(null));
public string Firstname {
get { return (string)GetValue(FirstnameProperty); }
set { SetValue(FirstnameProperty, value); }
}

public static readonly DependencyProperty WorkstationProperty = DependencyProperty.Register("Workstation", typeof(string), typeof(clsLvItemHelperOutput), new UIPropertyMetadata(null));
public string Workstation {
get { return (string)GetValue(WorkstationProperty); }
set { SetValue(WorkstationProperty, value); }
}

public static readonly DependencyProperty WDProperty = DependencyProperty.Register("WD", typeof(string), typeof(clsLvItemHelperOutput), new UIPropertyMetadata(null));
public string WD {
get { return (string)GetValue(WDProperty); }
set { SetValue(WDProperty, value); }
}

public static readonly DependencyProperty DayProperty = DependencyProperty.Register("Day", typeof(string), typeof(clsLvItemHelperOutput), new UIPropertyMetadata(null));
public string Day {
get { return (string)GetValue(DayProperty); }
set { SetValue(DayProperty, value); }
}

public static readonly DependencyProperty CWProperty = DependencyProperty.Register("CW", typeof(string), typeof(clsLvItemHelperOutput), new UIPropertyMetadata(null));
public string CW {
get { return (string)GetValue(CWProperty); }
set { SetValue(CWProperty, value); }
}

public static readonly DependencyProperty BeginProperty = DependencyProperty.Register("Begin", typeof(string), typeof(clsLvItemHelperOutput), new UIPropertyMetadata(null));
public string Begin {
get { return (string)GetValue(BeginProperty); }
set { SetValue(BeginProperty, value); }
}

public static readonly DependencyProperty EndProperty = DependencyProperty.Register("End", typeof(string), typeof(clsLvItemHelperOutput), new UIPropertyMetadata(null));
public string End {
get { return (string)GetValue(EndProperty); }
set { SetValue(EndProperty, value); }
}

public static readonly DependencyProperty AutoLogoffProperty = DependencyProperty.Register("AutoLogoff", typeof(string), typeof(clsLvItemHelperOutput), new UIPropertyMetadata(null));
public string AutoLogoff {
get { return (string)GetValue(AutoLogoffProperty); }
set { SetValue(AutoLogoffProperty, value); }
}

public static readonly DependencyProperty WTProperty = DependencyProperty.Register("WT", typeof(string), typeof(clsLvItemHelperOutput), new UIPropertyMetadata(null));
public string WT {
get { return (string)GetValue(WTProperty); }
set { SetValue(WTProperty, value); }
}

public static readonly DependencyProperty GAPProperty = DependencyProperty.Register("GAP", typeof(string), typeof(clsLvItemHelperOutput), new UIPropertyMetadata(null));
public string GAP {
get { return (string)GetValue(GAPProperty); }
set { SetValue(GAPProperty, value); }
}

public static readonly DependencyProperty PauseProperty = DependencyProperty.Register("Pause", typeof(string), typeof(clsLvItemHelperOutput), new UIPropertyMetadata(null));
public string Pause {
get { return (string)GetValue(PauseProperty); }
set { SetValue(PauseProperty, value); }
}

public static readonly DependencyProperty BeginCorrProperty = DependencyProperty.Register("BeginCorr", typeof(string), typeof(clsLvItemHelperOutput), new UIPropertyMetadata(null));
public string BeginCorr {
get { return (string)GetValue(BeginCorrProperty); }
set { SetValue(BeginCorrProperty, value); }
}

public static readonly DependencyProperty EndCorrProperty = DependencyProperty.Register("EndCorr", typeof(string), typeof(clsLvItemHelperOutput), new UIPropertyMetadata(null));
public string EndCorr {
get { return (string)GetValue(EndCorrProperty); }
set { SetValue(EndCorrProperty, value); }
}

public static readonly DependencyProperty WTCorrProperty = DependencyProperty.Register("WTCorr", typeof(string), typeof(clsLvItemHelperOutput), new UIPropertyMetadata(null));
public string WTCorr {
get { return (string)GetValue(WTCorrProperty); }
set { SetValue(WTCorrProperty, value); }
}

public static readonly DependencyProperty GAPCorrProperty = DependencyProperty.Register("GAPCorr", typeof(string), typeof(clsLvItemHelperOutput), new UIPropertyMetadata(null));
public string GAPCorr {
get { return (string)GetValue(GAPCorrProperty); }
set { SetValue(GAPCorrProperty, value); }
}

public static readonly DependencyProperty RemarkProperty = DependencyProperty.Register("Remark", typeof(string), typeof(clsLvItemHelperOutput), new UIPropertyMetadata(null));
public string Remark {
get { return (string)GetValue(RemarkProperty); }
set { SetValue(RemarkProperty, value); }
}

public static readonly DependencyProperty PrintModelIDProperty = DependencyProperty.Register("PrintModelID", typeof(string), typeof(clsLvItemHelperOutput), new UIPropertyMetadata(null));
public string PrintModelID {
get { return (string)GetValue(PrintModelIDProperty); }
set { SetValue(PrintModelIDProperty, value); }
}

public static readonly DependencyProperty FIDProperty = DependencyProperty.Register("FID", typeof(string), typeof(clsLvItemHelperOutput), new UIPropertyMetadata(null));
public string FID {
get { return (string)GetValue(FIDProperty); }
set { SetValue(FIDProperty, value); }
}


public static readonly DependencyProperty IsPublicHolidayProperty = DependencyProperty.Register("IsPublicHoliday", typeof(Boolean), typeof(clsLvItemHelperOutput), new UIPropertyMetadata(null));
public Boolean IsPublicHoliday {
get { return (Boolean)GetValue(IsPublicHolidayProperty); }
set { SetValue(IsPublicHolidayProperty, value); }
}
}
01.04.2015
tschroeer 35 1 4
0
Ich habe jetzt in der AssemblyInfo.cs eine Ergänzung gemacht:

[assembly: XmlnsDefinition("urn:double-d-it","WorktimeTrackerReport.Helperclasses")]


und die XAML angepasst:

<Window x:Class="WorktimeTrackerReport.frmMain"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="urn:double-d-it"
Title="WorktimeTracker - Verwaltung" Height="696.321" Width="929.955" Loaded="Window_Loaded" WindowStartupLocation="CenterScreen" ResizeMode="NoResize" Icon="Icons/timestamp.ico" Background="#FFFBF6F6">
<Window.Resources>
<local:ListViewItemStyleSelector x:Name="myStyleSelector" />
<Style TargetType="{x:Type TextBlock}"
x:Key="GridBlockStyle">
<Setter Property="VerticalAlignment" Value="Center" />
<Setter Property="Visibility"
Value="{Binding Path=IsSelected,
RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ListViewItem}},
ConverterParameter=False}" />
</Style>
</Window.Resources>


Jetzt bekomme ich für diese Zeile
<local:ListViewItemStyleSelector x:Name="myStyleSelector" />


diese Fehlermeldung:

Each dictionary entry must have an associated key.

Was soll das denn jetzt? Ich habe hier nirgends ein Dictionary!

BITTE HILFE !!!
02.04.2015
tschroeer 35 1 4
Schreib x:Key statt x:Name.
ffordermaier 02.04.2015
Habe ich gemacht. Jetzt findet er wieder die Klasse nicht ;-(((
tschroeer 02.04.2015
0
Hallo,
die Klasse müsste nach meinem Wissen einen leeren Konstruktor haben, um im XAML erkannt zu werden.

public lsLvItemHelperOutput()
{ }
18.06.2015
Frank_Sa 1 1

Stelle deine .net-Frage jetzt!
TOP TECHNOLOGIES CONSULTING GmbH