I'm trying to display an image for a row when that row has a file (in this case a PDF) attached to it. I have a True/False column called 'FileExists' which indicates if the row has a document associated with it.
So based on this this those rows that have a True value in the FileExists column should display an image. I want the ability then to allow the user to click the image to open the assigned PDF file.
I have had a few attempts at this now based on other posts but can quite get it to work properly.
Any help would be most appreciated.
Troy
Hello Troy,
Thank you for your post. I have been looking into your requirement and I created a sample project for you with the functionality you want. Basically I created a Style for the CellValuePresenter of the Boolean Field and change its ControlTemplate to has an Image and added a Converter to set different Images depending on the value of the Field. Also I bind the IsEnabled Property to the value, too, so that only the images of the records that has File can be clicked. Please let me now if this helps you or you need further assistance on this matter.
Looking forward for your reply.
Thanks Stefan! That worked like a charm, exactly what I was trying to achieve. Much appreciated.
Here it is shown how to use MultiBinding:
http://msdn.microsoft.com/en-us/library/system.windows.data.multibinding.aspx
Hope this helps you.
I'm very close now...I'm just having a problem getting the value of the other column... keep getting {DependencyProperty.UnsetValue}
I'm thinking I'm not referencing the column name 'MessageType' properly, I've tried everyting I can think of like 'DataContext.MessageType', etc.... I' must be missing some silly thing here. The binding to 'Value' gets the current column value just fine.
<Image.Source>
<MultiBinding Converter="{StaticResource directionConverter}" >
<Binding Path="Value" />
<Binding Path="MessageType" />
</MultiBinding>
</Image.Source>
I'm setting the DataContext in the Constructor of the userControl,
adapter.Connection.ConnectionString =
new Database(messageInfo.DatabaseGuid).GetDatabaseConnectionString();
adapter.Fill(dataset.tMessageTransaction, (int)messageInfo.TransactionType, messageInfo.TransactionId);
this.DataContext = dataset.tMessageTransaction.DefaultView;
Thanks in advance for any suggestions you may have.
Hello,
I can suggest you try DataItem.MessageType instead of just MessageType.
No luck... so frustrating...I've looked at numerous samples and cannot figure out why it will not work. I've attached the class file in case you get a chance to have a look.
thanks for you time.
You can try to get the Field by its name like this in the Binding's Path:
<Binding Path="Cells[MessageType].Value" />
Thank you for your feedback. I am glad that you resolved your issue and I believe that other community members may benefit from this as well.
Thanks again.
thanks Stefan that binding change worked. I also had to make a change in my MultiValueConverter class to use the ImageSourceConverter class rather than just returning a string as the image source.
new ImageSourceConverter().ConvertFromString(imagePath + "EmailReceived.png");
thanks so much.
I can suggest you change the Binding like this:
<Binding RelativeSource="{RelativeSource AncestorType={x:Type igDP:CellValuePresenter}}" Path="Record.Cells[MessageType].Value"/>
Hi Stefan,
I've generated a sample project, in it is a SQL script to run to create the dependent table and inserts 2 rows of test data, also you will need to alter the connection string which I've hardcoded for the sample purpose.
You will single a single converter as well which also displays images which is working, as you'll see when you run the app. That one is fine, it the multi converter column I'm having the issue with, the field is called 'Direction'.
Hopefully, you can see what I'm missing.
Thansk,
It seems like that your DataContext is set to CellValuePresenter, so you have to set the Binding's Path to Record.Cells["MessageType"].Value. If this doesn't help you, could you please send me an isolated sample project, where your issue is reproduced, so I can investigate it further for you.