Home Forums WPF controls Xceed DataGrid for WPF ResourceReferenceKeyNotFoundException

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #25250 |

    Hi all,

    I have the following XAML:

    <Window x:Class=”Fugro.Framework.UI.ModifyPersonnel”
    xmlns=”http://schemas.microsoft.com/winfx/2006/xaml/presentation&#8221;
    xmlns:x=”http://schemas.microsoft.com/winfx/2006/xaml&#8221;
    xmlns:datagrid=”http://schemas.xceed.com/wpf/xaml/datagrid&#8221;
    SizeToContent=”WidthAndHeight”
    >
    <Window.Resources>
    <DataTemplate x:Key=”dateOnTemplate”>
    <TextBlock Text=”{Binding Converter={StaticResource dateTimeConverter}}” />
    </DataTemplate>
    </Window.Resources>

    <Grid>
    <datagrid:DataGridControl CellEditorDisplayConditions=”MouseOverCell” EditTriggers=”ClickOnCurrentCell” ItemScrollingBehavior=”Immediate”
    Name=”mainGrid”>
    <datagrid:DataGridControl.View>
    <!– Default view –>
    <datagrid:TableView Theme=”{DynamicResource defaultTheme}”/>
    </datagrid:DataGridControl.View>

    <datagrid:DataGridControl.Columns>
    <!–Pre-configure the Columns of the grid–>
    <datagrid:Column FieldName=”Name” Title=”Employee Name” VisiblePosition=”0″ IsMainColumn=”True” />
    <datagrid:Column FieldName=”Function” Title=”Function” VisiblePosition=”1″ />
    <datagrid:Column FieldName=”DateOn” Title=”Date On” VisiblePosition=”2″ CellContentTemplate=”{StaticResource dateOnTemplate}”/>
    <datagrid:Column FieldName=”DateOff” Title=”Date Off” VisiblePosition=”3″ CellContentTemplate=”{StaticResource dateOnTemplate}”/>
    </datagrid:DataGridControl.Columns>
    </datagrid:DataGridControl>
    </Grid>
    </Window>

    <u>Converter:</u>

    public class DateTimeToTimeAbsoluteConverter : IValueConverter
    {
    public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
    {
    if (value is TimeAbsolute)
    {
    TimeAbsolute timeAbsolute = (TimeAbsolute)value;
    if (timeAbsolute.Equals(TimeAbsolute.Zero))
    {
    return null;
    }

    return new DateTime(timeAbsolute.DateTime.Year, timeAbsolute.DateTime.Month, timeAbsolute.DateTime.Day);
    }

    return new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day);
    }

    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
    {
    if (value is DateTime)
    {
    return new TimeAbsolute((DateTime)value, 0);
    }

    return TimeAbsolute.Zero;
    }

    The DateOn and the DateOff are of the type TimeAbsolute, which we use in our company instead of DateTime. My problem is that the exception: <b>System.Windows.ResourceReferenceKeyNotFoundException</b> is being thrown for the TimeAbsolutes, and since this Exception is caught by the application, I get a MessageBox every time the Grid is loaded, and every time I hover over the Cells. 🙁

    Any help on how to zap this Exception would be much appreciated.

    Thanks in advance,
    Frances

    Imported from legacy forums. Posted by Frances (had 4996 views)

    Xceed Support
    Member
    Post count: 5658

    Can you provide the call stack for the exception ? I think I know that the exception is, but I’d like to ensure before answering.

    Imported from legacy forums. Posted by Marcus [Xceed] (had 406 views)

    User (Old forums)
    Member
    Post count: 23064

    Hmmm… I can’t provide a Stack Trace. Either I catch the Exception and the Stack Trace tells you nothing useful, or I don’t catch it and then it doesn’t bother me. I do have some more info on the Exception: System.Windows.ResourceReferenceKeyNotFoundException: ‘Primitives.TimeAbsolute’ resource not found.

    Imported from legacy forums. Posted by Frances (had 839 views)

    User (Old forums)
    Member
    Post count: 23064

    * Bump *

    Imported from legacy forums. Posted by Frances (had 396 views)

    User (Old forums)
    Member
    Post count: 23064

    * Bump *

    * Bump *

    Imported from legacy forums. Posted by Frances (had 472 views)

    Xceed Support
    Member
    Post count: 5658

    Hi,

    Without the exception trace, there isn’t much we can do but throw wild guesses. I indicated previously that I tought I might know what the exception was… And I still can tell you this
    “assumption”, but it should be considered for what it is: a wild guess.

    In this case, I think the exception is one that is normally thrown by the default cell editor selector that uses the type of the data cell to determine if a default editor exists for it. In this case, the exception is explicitly suppressed and does not resurfaces up to user code.

    Since you mention that the exception does not annoy you if you don`t catch it. I suggest not catching it.

    Imported from legacy forums. Posted by Marcus [Xceed] (had 490 views)

    User (Old forums)
    Member
    Post count: 23064

    Marcus,

    I think he ran into the same problem I got. When you look for a template to display in any column, you will use FindResource(object.Type) instead of TryFindResource(object.Type). So if I hook up to DispatcherExceptionHandler, I will get ResournceNotFoundException although it doesn’t mean anything…

    Imported from legacy forums. Posted by nat (had 5705 views)

Viewing 7 posts - 1 through 7 (of 7 total)
  • You must be logged in to reply to this topic.