Click here to Skip to main content
15,917,320 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,

I have a database table with paths of images found on the pc. I want to load each image directly by it's path. The only part i cant workout is the Path Binding with the image source. This is what I've got till now:

//a control template to make an image button
<ControlTemplate x:Key="btnTemplate" TargetType="{x:Type Button}">
<Image x:Name="btnImage" Source="{Binding ButtonImage}"/>
</ControlTemplate>



private string ButtonImage;

private void AddElements()
{

Style buttonStyle = this.Resources["btnTemplate"] as Style;

//get categories
localhost.DSDatabase.tblCategoriesDataTable dtCat = new localhost.WSLService().GetCategories();

foreach(localhost.DSDatabase.tblCategoriesRow category in dtCat)
{
Button btn = new Button();
btn.Name = "btnCat"+category.category_id.ToString();
btn.Style = buttonStyle;
ButtonImage = category.menu_img;
Panel.Children.Add();
}
}

The problem is that nothing loads and no binding is being made from the image part. Is there any alternate/better way to do this?
Posted

1 solution

I can't quite figure out what you are trying to do here. But if you are trying to bind to ButtonImage in whatever class your code snippet is from, you can't. ButtonImage is a private field in your class. You need a public property for binding. Use a dependency property for ButtonImage.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900