Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Binding to Converter
Message
From
28/06/2013 20:13:47
 
 
To
27/06/2013 16:35:52
General information
Forum:
ASP.NET
Category:
Windows Presentation Foundation (WPF)
Environment versions
Environment:
C# 4.0
OS:
Windows Server 2012
Network:
Windows 2008 Server
Database:
MS SQL Server
Application:
Desktop
Miscellaneous
Thread ID:
01577175
Message ID:
01577467
Views:
40
Bump

Here's the code in my converter. Maybe I am missing a null check somewhere that someone else can see?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Data;
using System.Windows;
using SamaanSystems.IBC.Business;

namespace SamaanSystems.IBC.WPF
{
    public class Inv_PkToReceiptNumberConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {

            if (value == null || value.GetType() != typeof(Guid))
                return DependencyProperty.UnsetValue;

            Receipt receipt = new Receipt();
            ReceiptEntity re = receipt.GetReceiptByInvoicePK((Guid)value);

            if (re != null && re.rct_pk != Guid.Empty)
            {
                return re.rct_number;
            }
            else
            {
                CashReceipt cashReceipt = new CashReceipt();
                CashReceiptEntity cre = cashReceipt.GetCashReceiptByInvoicePK((Guid)value);

                if (cre != null && cre.crt_pk != Guid.Empty)
                {
                    return cre.crt_number;
                }
                else
                {
                    return DependencyProperty.UnsetValue;
                }

            }
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (value == null || value.GetType() != typeof(Guid))
                return Guid.Empty; 
            
            Receipt receipt = new Receipt();
            ReceiptEntity re = receipt.GetReceiptByNumber(System.Convert.ToInt32(value));

            if (re != null)
            {
                return re.rct_pk;
            }
            else
            {
                CashReceipt cashReceipt = new CashReceipt();
                CashReceiptEntity cre = cashReceipt.GetCashReceiptByNumber(System.Convert.ToInt32(value));

                if (cre != null)
                {
                    return cre.crt_pk;
                }
                else
                {
                    return Guid.Empty;
                }
            }
        }
    }
}
>Just bumping this in case everybody missed it. It's still not completely solved. :(
>
>>Update
>>
>>I solved this. I had not completed the ConvertBack of the converter. When I added that code in and rebuilt the solution it all worked as desired EXCEPT that the designer gives me "An Unhandled Exception has occurred". This is the detail of the error:
>>
>>System.Reflection.TargetInvocationException
>>Exception has been thrown by the target of an invocation.
>> at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
>> at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
>> at System.Delegate.DynamicInvokeImpl(Object[] args)
>> at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
>> at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)
>>
>>
>>System.NullReferenceException
>>Object reference not set to an instance of an object.
>> at OakLeaf.MM.Main.mmAppBase.get_DatabaseMgr()
>> at OakLeaf.MM.Main.Business.mmBusinessObject.GetDataAccessObject(String databaseKey, Boolean localDataAccessObject)
>> at OakLeaf.MM.Main.Business.mmBusinessObject.GetDataAccessObject(String databaseKey)
>> at OakLeaf.MM.Main.Business.mmBusinessObject.GetDataAccessObject()
>> at OakLeaf.MM.Main.Business.mmBusinessObject.CreateParameter(String name, Object value)
>> at SamaanSystems.IBC.Business.Receipt.GetReceiptByInvoicePK(Guid invoicePK) in D:\Development\VS2010\IBC\IBC Business Objects\Receipt\Receipt.Partial.cs:line 39
>> at SamaanSystems.IBC.WPF.Inv_PkToReceiptNumberConverter.Convert(Object value, Type targetType, Object parameter, CultureInfo culture) in D:\Development\VS2010\IBC\IBC WPF\Converters\Inv_PkToReceiptNumberConverter.cs:line 21
>> at System.Windows.Data.BindingExpression.TransferValue(Object newValue, Boolean isASubPropertyChange)
>> at System.Windows.Data.BindingExpression.Activate(Object item)
>> at System.Windows.Data.BindingExpression.AttachToContext(AttachAttempt attempt)
>> at System.Windows.Data.BindingExpression.MS.Internal.Data.IDataBindEngineClient.AttachToContext(Boolean lastChance)
>> at MS.Internal.Data.DataBindEngine.Task.Run(Boolean lastChance)
>> at MS.Internal.Data.DataBindEngine.Run(Object arg)
>> at MS.Internal.Data.DataBindEngine.OnLayoutUpdated(Object sender, EventArgs e)
>> at System.Windows.ContextLayoutManager.fireLayoutUpdateEvent()
>> at System.Windows.ContextLayoutManager.UpdateLayout()
>> at System.Windows.UIElement.UpdateLayout()
>> at System.Windows.Interop.HwndSource.SetLayoutSize()
>> at System.Windows.Interop.HwndSource.set_RootVisualInternal(Visual value)
>> at System.Windows.Interop.HwndSource.set_RootVisual(Visual value)
>> at MS.Internal.DeferredHwndSource.ProcessQueue(Object sender, EventArgs e)
>>
>>Anyone have a clue what this is trying to tell me?
>>
>>end of update
>>
>>Hi,
>>
>>I am trying to bind a textbox to a converter. This is to display the receipt number that the currently displayed invoice is on. So I set my XAML up like this:
>>
>>
>><Window.Resources>
>>        <local:Inv_PkToReceiptNumberConverter x:Key="Inv_PkToReceiptNumberConverter"/>
>></Window.Resources>
>>
>><TextBox Text="{Binding inv_pk, Converter={StaticResource Inv_PkToReceiptNumberConverter}, Mode=Default}" />
>>
>>But this gives me an error:
>>
>>"Object reference not set to an instance of an object"
>>
>>How do I get this to work?
Frank.

Frank Cazabon
Samaan Systems Ltd.
www.samaansystems.com
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform