|
Hi,
I want to asssociate a BitMap image with the ListboxItems in a WPF Listbox. But I could not find any property in the ListboxItem which can get associated with an image. I am loading the ListBox programatically and want to display images on the listboxitems dynamically.
Could anyone let me know how can i acheive this in the WPF ListBox?
Thanx in advance.
|
|
|
|
|
I would be tempted to do something like this:
<DataTemplate x:Key="MyTemplate">
<Grid>
<Grid.RowDefinitions>
<RowDefinition/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<Image Grid.Column=1 Width="{Binding myImage.Width}" Height="{Binding myImage.Height}" Source="{Binding myImage}" />
<TextBlock Width="Auto" Grid.Column="1"
Text="{Binding MyTextItem}" />
</Grid>
</DataTemplate> Then, your listbox would look like this:
<ListBox Padding="3" HorizontalAlignment="Left" Width="Auto"
ItemTemplate="{DynamicResource MyTemplate}"
ItemsSource="{Binding Mode=Default, Source={StaticResource MyDataSource}}"
VerticalAlignment="Top" Height="Auto"/>
|
|
|
|
|
Hi Pete,
Thanx for the reply.
My actual requirement is to load the listbox with ToolboxItems. Each ToolboxItem has its own image which i want to associate with the listboxitem when i create a new listboxitem. I tried multiple ways of doing it programatically but unable to get the desired result.
Without using the xaml file how can i add items to the listbox programatically. One of the ways is setting the ItemsSource property to collection containing the items. I could populate a Treeview just by creating new TreeviewItems in the code and adding them to the Treeview.But the same did not happen incase of Listbox, am I missing anything?
Also, I am unable to group items within the listbox, could you please suggest how i can acheive this?
Thanx in adv.
|
|
|
|
|
Hi,
Also, using the DataTemplate given above I am not able to view any image on the Listboxitem. And sometime a XamlParseException is thrown at runtime, which is as follows
connot convert string in attribute 'Source' to object of type 'System.Windows.Media.ImageSource'
Any idea what am I missing? Is it that I cannot load a Bitmap image on the ListBoxItem??
|
|
|
|
|
I have a template and would like to access a UIElement. Because it is a template, it is not an object unless it is a static object. How can I create a static object in a template? The x:Name=”someName” are only to access inside template NOT outside. So we get an error when we try to access from a class. i.e. in constructor I can’t access someName. This also means that I cannot write a function when there is a change.
How this can be done?
Best regards
Agha
<Button x:Class="WpfApplication1.DoubleCharBtn"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Button.Template>
<ControlTemplate>
<Border x:Name="br" Background="Blue" CornerRadius="3" BorderBrush="Black">
<StackPanel Orientation="Vertical">
<TextBlock x:Name="TextUpperChar" HorizontalAlignment="Center" Text="{Binding UpperLetter}" />
<TextBlock x:Name="TextLowerChar" HorizontalAlignment="Center" Text="{Binding LowerLetter}" />
</StackPanel>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="Button.IsPressed" Value="True">
<Setter TargetName="br" Property="Background" Value="Red"/>
<Setter TargetName="TextUpperChar" Property="Background">
<Setter.Value>
<LinearGradientBrush>
<GradientStop Offset="1" Color="DarkBlue"/>
<GradientStop Offset="0.5" Color="Blue"/>
<GradientStop Offset="0" Color="DarkBlue"/>
</LinearGradientBrush>
</Setter.Value>
</Setter>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Button.Template>
</Button>
namespace WpfApplication1
{
/// <summary>
/// Interaction logic for DoubleCharBtn.xaml
/// </summary>
public partial class DoubleCharBtn : Button
{
internal static readonly DependencyProperty UpperCharProperty =
DependencyProperty.Register(
"UpperChar",
typeof(char),
typeof(DoubleCharBtn),
new FrameworkPropertyMetadata(' ', FrameworkPropertyMetadataOptions.AffectsMeasure | FrameworkPropertyMetadataOptions.AffectsRender, UpperCharChanged));
public static void UpperCharChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
char TempChar = (char)e.NewValue;
DoubleCharBtn doubleCharBtn = (DoubleCharBtn)d;
// doubleCharBtn.TextUpperChar.Text = string.Format("{0}",TempChar);
}
public char UpperChar
{
set { SetValue(UpperCharProperty, value); }
get { return (char)GetValue(UpperCharProperty); }
}
internal static readonly DependencyProperty LowerCharProperty =
DependencyProperty.Register(
"LowerChar",
typeof(char),
typeof(DoubleCharBtn),
new FrameworkPropertyMetadata(' ', FrameworkPropertyMetadataOptions.AffectsMeasure | FrameworkPropertyMetadataOptions.AffectsRender, LowerCharChanged));
public static void LowerCharChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
char TempChar = (char)e.NewValue;
DoubleCharBtn doubleCharBtn = (DoubleCharBtn)d;
// doubleCharBtn.TextLowerChar.Text = string.Format("{0}", TempChar);
}
public char LowerChar
{
set { SetValue(LowerCharProperty, value); }
get { return (char)GetValue(LowerCharProperty); }
}
public DoubleCharBtn()
{
InitializeComponent();
}
}
}
|
|
|
|
|
|
Hi,
I try to leave my control as thay are in case i maximaize my window - but i always find them in disorder in my window.
this is the xaml code ...
<StackPanel VerticalAlignment="Stretch" HorizontalAlignment="Stretch">
<TextBox Name="Title" Text="Title" Background="Yellow" Width="Auto" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" Height="30" VerticalAlignment="Top"/>
<ListView Name="RecentReport" Width="Auto" Height="180" VerticalAlignment="Center" HorizontalContentAlignment="Center" />
<StackPanel Height="52" Name="stackPanel1" Width="Auto" VerticalAlignment="Bottom" Background="Aqua" Orientation="Horizontal" />
</StackPanel>
|
|
|
|
|
Is this what you wanted?
<DockPanel LastChildFill="True" VerticalAlignment="Stretch" HorizontalAlignment="Stretch">
<TextBox DockPanel.Dock="Top" Name="Title" Text="Title" Background="Yellow" Height="30" />
<StackPanel DockPanel.Dock="Bottom" Height="52" Name="stackPanel1" Background="Aqua" Orientation="Horizontal" />
<ListView Name="RecentReport" />
</DockPanel>
|
|
|
|
|
Hi,
Does anybody know if VS2008 has an internal web browser, for launching Silverlight apps ? I believed have seen screenshots with that...
WolveFred
|
|
|
|
|
This one?
View/Other Windows/Web Browser (Ctrl-Alt-R)
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
No. I dont think VS 2008 has an internal web browser. not even in VS2010..
|
|
|
|
|
That's not true : there is one.
* Right click a page (.aspx, or on a folder)
* Select Browse With...
* Choose your browser : internal
* Click Set as Default
* Click Browse
|
|
|
|
|
Working through this... just completed part 3.
Accessing the ASP.NET Authentication, Profile and Role Service in Silverlight[^]
I can't get the images to appear in Firefox but I can in IE and Google Chrome - despite the fact that the latter is not "officially" supported. ???
Any ideas for things to tweak in Firefox?
Update: It now works as of this morning - no code changes. Must have been a caching issue.
Kevin
modified on Sunday, February 8, 2009 1:17 PM
|
|
|
|
|
It should work in Firefox as well.
Are you using that sample or did you change something in that sample?
|
|
|
|
|
It works now (tried again this morning) so must have been a caching problem.
Kevin
|
|
|
|
|
okay. Great!
|
|
|
|
|
Can any one tell me, if I need to populate the items of a Panel dynamically using Binding, how can I do so?
A panel has got a Children property, unlike other collection control ListView, Listbox that offers a property named ItemsSource or stuffs like that. How can i make this thing work for a panel.
To clarify the question- How to bind the items displayed inside a FishEyePanel ..or is it possible at all?
usually, What I can do is
<stackpanel>
however, I want to generate the number of button using Binding...is it possible?
Moim Hossain
R&D Project Manager
BlueCielo ECM Solutions BV
|
|
|
|
|
What I would do here is put a ListView inside your panel, and then generate the buttons inside ListView Items.
|
|
|
|
|
hmm nope,
I got my problems solutions ..
<ItemsControl ItemsSource="{Binding ConfiguredViews}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<panels:FishEyePanel/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
here is what I was thinking.
Thanks for bothering :P
Moim Hossain
R&D Project Manager
BlueCielo ECM Solutions BV
|
|
|
|
|
Hi,
i need to create a software (about restaurant,hotel,etc..etc..),
an important request i received from my manager is to create a Forms Authentication with many different Login and Passwords where each user will get a different privilege to restrict the access.
An example:
- Login = guest ...can only access to the software without delete,add or edit the data.
- Login = adminstrator ... can do everything .
- Login = employee 01 ... can access to the software but can delete,add and edit just some (specific) data.
- Login = employee 02 .... can access to the software but can delete,add and edit just some (specific) data.
..... and so on ...
This software will be used in 5 different department in my office so each department will have different privilege/permission to access in the software.
Now i have not a clear idea to develop this feature ,never i made it as my knowledge are poor.
I will use SqlServer 2005 for the database ,Linq toSql and Wpf(interface) of course so i thought to create a table with SqlServer as follow:
CREATE TABLE [dbo].[TblLogin] (
[Name] [varchar] (30) ,
[username] [varchar] (20),
[password] [varchar] (20) ,
[Email] [varchar] (50) ,
[Roles] [varchar] (50)
)
GO
but after i get stuck i don't know how go ahead
If you have any idea/suggestion let me know it will be so useful for me,i'm available to learn ...i have a lot of thing to learn .
Have a good job.
Nice Regards,
Bye
|
|
|
|
|
Well, you could always use the MembershipProvider and RolesProvider classes. To use these, you need to add the relevant tables into SQL Server (added by the command aspnet_regsql[^]). Then, you need to add a System.Web entry into your config file, and add the MembershipProvider and RoleProvider sections in here. That's it - you now have access to a role mechanism. It's up to you to provide the login screen and admin screens, but that should be fairly trivial.
|
|
|
|
|
Hi Pete
for my poor knowledge never i used a System.Web in past time so i have some question to understand better what i need to do but before to post my question do you have some link to show me so i can ask not foolish question.
Thanks my friend
Have a nice job.
Bye
|
|
|
|
|
Here's a sample of what would go in your config file:
<system.web>
<membership defaultProvider="AspNetSqlProvider" />
<roleManager enabled="true" defaultProvider="AspNetSqlProvider" />
</system.web>
<connectionStrings>
<remove name="LocalSqlServer" />
<add name="LocalSqlServer" connectionString="
data source=(local);Integrated Security=SSPI;
Initial Catalog=aspnetdb" />
</connectionStrings>
|
|
|
|
|
Hi Pete,
sorry if i ask you many question but when i don't understand i can not go ahead....
I tried your advice it is right , now i have the aspnetdb.mdf in my WPF project.
Sincerily i have not experience about Roles and MembershipProvider so i ask you if you have some link where learn some step to go ahead ...
Thanks a lot .
Have a nice wake up.
Bye
|
|
|
|
|
If you can wait a couple of days, I'm writing a RoleManager in WPF application that I will be posting up (possibly as an article - or possibly on my blog), which will provide a fairly complete implementation that demonstrates how to use Roles and the Membership API, especially with regards to the MVVM pattern. Trust me - all becomes clear when you see the code.
If you can't wait that long, you can get some ideas from here[^] and here[^] (note you need to add a reference to System.Web to your application to get this to work).
|
|
|
|