Using Caliburn.Micro cal:Message.Attach does a No target found for method - menuitem

I have created dynamic MenuItems with the last recent open folders. This works well.
Now, beacause these MenuItems are created dynamically, when I click on one MenutItem, I would like to raise an action and give the header of the MenuItem as a parameter.
So this is my "MainView.xaml"
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:diag="clr-namespace:System.Diagnostics;assembly=WindowsBase"
xmlns:common="clr-namespace:Common;assembly=RecentFileListLib"
xmlns:cal="http://www.caliburnproject.org"
xmlns:self="clr-namespace:MainUI.Models"
xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
xmlns:ViewModels="clr-namespace:MainUI.ViewModels" xmlns:local="clr-namespace:MainUI.Views" x:Name="window" x:Class="MainUI.Views.MainView"
mc:Ignorable="d"
Title="MainView" Height="450" Width="800">
<Window.Resources>
<self:DebugDummyConverter x:Key="DebugDummyConverter" />
</Window.Resources>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="20"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="20"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="20"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
<RowDefinition Height="20"/>
</Grid.RowDefinitions>
<Menu Grid.Row="0" Grid.Column="1" Grid.ColumnSpan="4" Margin="0">
<MenuItem x:Name="menuItem" Header="_File">
<MenuItem Header="_Open" x:Name="FileOpen"/>
<MenuItem x:Name="RecentProject" Header="Recents Projects" >
<MenuItem.ItemTemplate >
<DataTemplate >
<MenuItem Header="{Binding DisplayPath, Converter={StaticResource DebugDummyConverter}}" cal:Message.Attach="Remove($dataContext)"/>
</DataTemplate>
</MenuItem.ItemTemplate>
</MenuItem>
</MenuItem>
</Menu>
<StackPanel Orientation="Vertical" Grid.Row="2" Grid.Column="1" Grid.RowSpan="1" Margin=" 0 0 10 0" >
<Button x:Name="LoadUser" Content="Load User Page" />
</StackPanel>
<ContentControl Grid.Row="1" Grid.Column="2" Grid.ColumnSpan="1" Grid.RowSpan="2" x:Name="ActiveItem"/>
<StatusBar Grid.Row="4" Grid.Column="1" Grid.ColumnSpan="2">
<StatusBar.ItemsPanel>
<ItemsPanelTemplate>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="100" />
</Grid.ColumnDefinitions>
</Grid>
</ItemsPanelTemplate>
</StatusBar.ItemsPanel>
<StatusBarItem Grid.Column="1">
<TextBlock Text="{Binding FolderPath}" />
</StatusBarItem>
</StatusBar>
</Grid>
For this I'm using cal:Message.Attach="Remove($dataContext)
And in my view model "MainViewModel"
public partial class MainViewModel : Conductor<Object>
{
public BindableCollection<RecentFile> RecentProject { get; private set; } = new BindableCollection<RecentFile>();
public string FolderPath { get; set; }
public MainViewModel()
{
Persister = new RegistryPersister();
MaxNumberOfFiles = 9;
MaxPathLength = 50;
MenuItemFormatOneToNine = "_{0}: {2}";
MenuItemFormatTenPlus = "{0}: {2}";
RemoveMenuItems();
LoadRecentFiles();
}
public void Remove(Object child)
{
}
By doing it like this, when I click on my menuitem I have a message "No target found for method Remove."
If someone can help me.
Thanks in advance

You could make use of cal:Action:TargetWithoutContext. For example,
cal:Action.TargetWithoutContext="{Binding ElementName=RecentProject, Path=DataContext}"
Complete Code
<MenuItem x:Name="RecentProject" Header="Recents Projects" Tag="{Binding}">
<MenuItem.ItemTemplate >
<DataTemplate >
<MenuItem Header="{Binding DisplayPath}" cal:Message.Attach="Remove($dataContext)" cal:Action.TargetWithoutContext="{Binding ElementName=RecentProject, Path=DataContext}"/>
</DataTemplate>
</MenuItem.ItemTemplate>
</MenuItem>

Related

Xamarin MVVM Display Data From Another Model/Table/Object

New to Xamarin. What is the best way to display data I need from another table/model/object? Or don't at all?
I want to try System.Linq's Enumerable.Join but doesn't that defeat the purpose of an observable collection? I want to change things and insert records. I've been trying to use another model to group the information together but no luck.
Trying to use a carousel view with another group model wrapped around the info. Questions are coming from a working API. Thanks all.
Question
qQuestion
name
Answer
pAnswer
fQuestion
Value
Comments
ViewModel
IEnumerable<QuestionModel> questions = await DataSource.GetQuestionsAsync(true);
QuestionList.Clear();
int k = 0;
foreach (var i in q)
{
// questions for template
QuestionList.Add(i);
var c = k++;
string s = (c + 1).ToString();
var a = new AnswerModel
{
pAnswer = s,
Posted = DateTime.Now,
fQuestion = i.pQuestion,
Value = i.Standard,
Comments = "Commnt here"
};
// template of answers for each question
AnswerCollection.Add(a);
}
// templates
foreach (var i in AnswerCollection)
{
var n = new GroupList<QuestionModel>
{
pGroup = i.pQuestion.ToString(),
Name = i.Name
};
n.Add(i);
GroupedAnswerCollection.Add(n);
}
//var g = AnswerCollection.Join(
// QuestionList,
// foreign => foreign.fQuestion,
// primary => primary.pQuestion,
// (primary, foreign) => new
// {
// Test = primary.pAnswer,
// Test2 = foreign.Name,
// }).ToList();
Xaml
<CarouselView ItemsSource="{Binding GroupedCollection}"
HorizontalOptions="FillAndExpand"
VerticalOptions="FillAndExpand">
<CarouselView.ItemTemplate>
<DataTemplate>
<StackLayout>
<Frame BorderColor="DarkGray"
Margin="20"
WidthRequest="200"
HorizontalOptions="Center"
VerticalOptions="CenterAndExpand">
<StackLayout>
<StackLayout>
<Label Text="{Binding pGroup}"></Label>
<Label Text="{Binding Name}"></Label>
<Label Text="{Binding Other}"></Label>
</StackLayout>
<StackLayout>
<Label Text="{Binding pAnswer}"></Label>
<Label Text="{Binding fQuestion}" ></Label>
<Label Text="{Binding Value}" ></Label>
<Label Text="{Binding Comments}" ></Label>
</StackLayout>
</StackLayout>
</Frame>
</StackLayout>
</DataTemplate>
</CarouselView.ItemTemplate>
</CarouselView>
View:
<CarouselView ItemsSource="{Binding GroupedCollection}"
HorizontalOptions="FillAndExpand"
VerticalOptions="FillAndExpand">
<CarouselView.ItemTemplate>
<!--All properties inside this data template need to exist in the QuestionAnswer object -->
<DataTemplate>
<StackLayout>
<Frame BorderColor="DarkGray"
Margin="20"
WidthRequest="200"
HorizontalOptions="Center"
VerticalOptions="CenterAndExpand">
<StackLayout>
<StackLayout>
<Label Text="{Binding pGroup}"></Label>
<Label Text="{Binding Name}"></Label>
<Label Text="{Binding Other}"></Label>
</StackLayout>
<StackLayout>
<Label Text="{Binding pAnswer}"></Label>
<Label Text="{Binding fQuestion}" ></Label>
<Label Text="{Binding Value}" ></Label>
<Label Text="{Binding Comments}" ></Label>
</StackLayout>
</StackLayout>
</Frame>
</StackLayout>
</DataTemplate>
</CarouselView.ItemTemplate>
</CarouselView>
ViewModel:
Backing property for the carousel view.
private IEnumerable<QuestionAnswer> groupedCollection;
public IEnumerable<QuestionAnswer> GroupedCollection
{
get => groupedCollection;
set
{
groupedCollection = value;
OnPropertyChanged(nameof(GroupedCollection));
}
}
//Can pull information from multiple sources and package it for the view.
private void GetQuestionAnswers()
{
//pulling data from 2 separate sources
var questions = await QuestionApi.GetQuestions();
var answers = await AnswersApi.GetAnswers();
//use these to build QuestionAnswer list called questionAnswerList
GroupedCollection = questionAnswerList;
}
Hopefully this helps.

CryptQueryObject systematically falls

I try to integrate root certificate installation within my programm installer. I have to create an object from certificate and then add it to the store.
const std::string cert = R"cert(
-----BEGIN CERTIFICATE-----
/***/
-----END CERTIFICATE-----
)cert";
PCCERT_CONTEXT pCertCtx = NULL;
CRYPT_INTEGER_BLOB blob;
blob.pbData = (BYTE*)cert.c_str();
bool result = CryptQueryObject(CERT_QUERY_OBJECT_BLOB, &blob,
CERT_QUERY_CONTENT_FLAG_CERT,
CERT_QUERY_FORMAT_FLAG_BASE64_ENCODED,
0, NULL, NULL, NULL, NULL, NULL, (const void**)&pCertCtx);
if (!result) {
DWORD errorMessageID = ::GetLastError();
LPSTR messageBuffer = nullptr;
size_t size = FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
NULL, errorMessageID,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPSTR)&messageBuffer, 0, NULL);
std::string message(messageBuffer, size);
//Free the buffer.
LocalFree(messageBuffer);
return ERROR_INSTALL_FAILURE;
}
I make my own dll with this custom action and add this to WiX.
<Binary Id="pathFixer" SourceFile="$(var.product.inputFilesDir)\path-fixer.dll" />
<Binary Id="additionalActions" SourceFile="$(var.product.inputFilesDir)\additional-actions.dll" />
<CustomAction Id="SetNativeMessageHostPath" BinaryKey="pathFixer" DllEntry="SetNativeMessageHostPath" Execute="deferred" Impersonate="no"/>
<CustomAction Id="SetInstallDir" Property="SetNativeMessageHostPath" Value="[INSTALLDIR]" Execute="immediate" />
<CustomAction Id="installRootCert" BinaryKey="additionalActions" DllEntry="installRootCert" Execute="deferred" Impersonate="no"/>
<CustomAction Id="ResetOldVersionFound" Property="OTHER_VERSION_FOUND" Value="" Execute="immediate" />
<CustomAction Id="GetPerUserOldVersionFound" Property="USER_OTHER_VERSION_FOUND" Value="[OTHER_VERSION_FOUND]" Execute="immediate" />
<CustomAction Id="GetPerMachineOldVersionFound" Property="MACHINE_OTHER_VERSION_FOUND" Value="[OTHER_VERSION_FOUND]" Execute="immediate" />
<CustomAction Id="SetPerUserOldVersionToRemove" Property="OTHER_VERSION_FOUND" Value="[USER_OTHER_VERSION_FOUND]" Execute="immediate" />
<CustomAction Id="SetPerMachineOldVersionToRemove" Property="OTHER_VERSION_FOUND" Value="[MACHINE_OTHER_VERSION_FOUND]" Execute="immediate" />
<InstallExecuteSequence>
<Custom Action="SetPerUserOldVersionToRemove" Before="RemoveExistingProducts">MSIINSTALLPERUSER=1</Custom>
<Custom Action="SetPerMachineOldVersionToRemove" Before="RemoveExistingProducts">MSIINSTALLPERUSER=""</Custom>
<Custom Action="SetInstallDir" After="InstallInitialize"/>
<RemoveExistingProducts After="InstallInitialize" />
<InstallExecute After="RemoveExistingProducts" />
</InstallExecuteSequence>
<Media Id="1" Cabinet="$(var.project.name).cab" EmbedCab="yes" CompressionLevel="high" />
<CustomAction Id="SetPerUserFolder" Directory="APPLICATIONFOLDER" Value="[AppDataFolder]" Execute="immediate" />
<CustomAction Id="SetPerMachineFolder" Directory="APPLICATIONFOLDER" Value="[ProgramFilesFolder]" Execute="immediate" />
<InstallExecuteSequence>
<Custom Action="SetPerUserFolder" After="CostFinalize">NOT Installed AND MSIINSTALLPERUSER=1</Custom>
<Custom Action="SetPerMachineFolder" After="SetPerUserFolder">NOT Installed AND MSIINSTALLPERUSER=""</Custom>
<Custom Action="SetNativeMessageHostPath" After="PublishProduct">NOT REMOVE</Custom>
<Custom Action="installRootCert" After="PublishProduct">NOT REMOVE</Custom>
</InstallExecuteSequence>
Debuging says directly that due installing functions is executed. But with some magic operations like join MessageBox, Debuging, i take from CryptQueryObject true and false periodcly, but not systematicly. GetLastError says Parameter is incorrect. Why could this happen?
I resolve it just adding the count, in bytes, of data, before call CryptQueryObject.
blob.cbData = cert.length();
Be careful with struct data.

Ending tag in XML child

I am having tough time writing a XML file. Everything is written perfectly, but the ending tag is missing.
Expected XML FILE:
<HEADER>
<CHILD Name="" Value = ""></CHILD>
<CHILD Name="" Value = ""><SUBSCHILD Name=""></SUBCHILD></CHILD>
<CHILD Name="" Value = ""></CHILD>
<CHILD Name="" Value = ""><SUBSCHILD Name=""></SUBCHILD></CHILD>
</HEADER>
Actual XML FILE:
<HEADER>
<CHILD Name="" Value = "">
<CHILD1 Name="" Value = ""><SUBSCHILD1 Name="">
<CHILD Name="" Value = "">
<CHILD1 Name="" Value = ""><SUBSCHILD1 Name="">
</HEADER>
Writing XML file:
QXmlGet xmlget;
xmlget.load(file.xml);
xmlget.findAndDescend("HEADER");
QxmlPut xmlput(xmlget);
for(int i=0; i<child.count(); i++)
{
xmlput.putString("CHILD", "")
xmlput.setAttributeString("Name", child.at(i).name);
xmlput.setAttributeString("Value", child.at(i).value);
if(child.at(i).Subchild.size() != 0)
{
xmlput.putString("SUBCHILD", "");
xmlput.setAttributeString("Name", child.at(i).subchild);
}
}
Everything works perfectly fine, except for the ending tag which spoils the whole XML file

How can I make a query that returns objects who contain all ids from list

I have two objects : Profile and Tags. Each profile can contain multiple tags. On my search page I can select multiple tags to search on. Now I want a query that get all profiles that have all the selected tags.
So if I use WhereRestrictionOn().IsIn() I get profiles which contains at least 1 of the tags but I need to return profiles which contains all the tags in the list.
I also tried multiple Where conditions for each selected tag but then I get no results at all.
I have no clue how to do this any help is much appreciated!
Structure:
Profile : Id
ProfileTag : ProfileId, TagId
Tag: Id
Mapping Profile
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" namespace="Agrolink.Application.Models" assembly="Agrolink.Application">
<class name="Agrolink.Application.Models.Profile" lazy="false" table="Profiles" >
<id name="Id" column="Id" >
<generator class="identity" />
</id>
<bag name="Tags" table="ProfileTags" cascade="all-delete-orphan" inverse="true">
<key column="IdProfile" not-null="true"/>
<one-to-many class="Agrolink.Application.Models.ProfileTag" />
</bag>
</class>
</hibernate-mapping>
Mapping ProfileTag
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" namespace="Agrolink.Application.Models" assembly="Agrolink.Application">
<class name="Agrolink.Application.Models.ProfileTag" lazy="false" table="ProfileTags" >
<id name="Id" column="Id" >
<generator class="identity" />
</id>
<many-to-one name="Profile" class="Agrolink.Application.Models.Profile" column="IdProfile" cascade="save-update" />
<many-to-one name="Tag" class="Agrolink.Application.Models.Tag" column="IdTag" cascade="none" />
</class>
</hibernate-mapping>
Mapping Tag
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" namespace="Agrolink.Application.Models" assembly="Agrolink.Application">
<class name="Agrolink.Application.Models.Tag" lazy="false" table="Tags" >
<id name="Id" column="Id" >
<generator class="identity" />
</id>
<property name="Name" column="Name" />
<property name="Type" type="Agrolink.Application.Models.TagType, Agrolink.Application" column="IdType" />
<many-to-one name="Parent" class="Agrolink.Application.Models.Tag" column="IdParent" cascade="none" />
<bag name="Children" table="Tags" cascade="all" inverse="true">
<key column="IdParent" not-null="true"/>
<one-to-many class="Agrolink.Application.Models.Tag" />
</bag>
</class>
</hibernate-mapping>
SubQuery to achieve this (Solution):
Profile p = null;
Account a = null;
Institute i = null;
var q = Session.QueryOver(() => p)
.JoinAlias(x => x.Account, () => a)
.JoinAlias(x => x.Institute, () => i)
.Where(x => x.Type == ProfileType.Expert && x.Status == ProfileStatus.Active);
if(_keywordIds.Any())
foreach (var keywordId in _keywordIds)
{
Tag t = null;
var subQ = QueryOver.Of<ProfileTag>()
.JoinAlias(pt => pt.Tag, () => t)
.Where(() => t.Id == keywordId)
.Select(pt => pt.Profile.Id);
q.WithSubquery.WhereProperty(() => p.Id).In(subQ);
}
if (_institute != null) q.Where(() => i.Id == _institute);
if (!string.IsNullOrEmpty(_name)) q.Where(Restrictions.Disjunction()
.Add(Restrictions.Like("a.FirstName", _name + "%"))
.Add(Restrictions.Like("a.LastName", _name + "%"))
);
return (PagedList<Profile>) q.List<Profile>().ToPagedList(_page, _itemsPerPage);
It is almost it, but we need so called Detached QueryOver, which we will get with construction QueryOver.Of
foreach (var keywordId in _keywordIds)
{
//Tag t = null;
var subQ = QueryOver.Of<ProfileTag>()
//.JoinAlias(pt => pt.Tag, () => t)
//.Where(() => t.Id == keywordId)
.Where(x => x.Tag.Id == keywordId)
//.Select(pt => t.Id);
.Select(pt => pt.Profile.Id);
q.WithSubquery.WhereProperty(() => p.Id).In(subQ);
}

Data is not visible in the list

In my Windows Phone 8 application when user clicks on the button, i'm calling the web service and get the result in the variable of type List.
After that I'm trying to bind the result to list in xaml page. But the data is not visible.
//Data Context object
class Company
{
public string CompanyId { get; set; }
public string CompanyName { get; set; }
public string CityId { get; set; }
public string Category { get; set; }
public string CategoryId { get; set; }
public string Address { get; set; }
public string Phone1 { get; set; }
public string Mobile1 { get; set; }
public string Email { get; set; }
public string Fax { get; set; }
public string Website { get; set; }
public string Profile { get; set; }
public string Latitude { get; set; }
public string Longitude { get; set; }
public string Sponsored { get; set; }
}
In my XAML page i'm binding the above result to List.
<Grid x:Name="ContentPanel" Grid.Row="3" Background="White" Margin="0,-3,0,0">
<ListBox x:Name="companiesList"
SelectionChanged="companiesList_SelectionChanged">
<ListBox.ItemTemplate>
<DataTemplate>
<Grid x:Name="listItem">
<Grid.RowDefinitions>
<RowDefinition Height="40"/>
<RowDefinition Height="30"/>
<RowDefinition Height="30"/>
<RowDefinition Height="10"/>
</Grid.RowDefinitions>
<TextBlock x:Name="nameTextBlock" Grid.Row="0" Text="{Binding CompanyName}" Foreground="#FF501F6E" Style="{StaticResource PhoneTextNormalStyle}" HorizontalAlignment="Left" FontSize="28" MaxHeight="40" TextTrimming="WordEllipsis" Margin="5,0,0,5"/>
<TextBlock x:Name="addressTextBlock" Grid.Row="1" Text="{Binding Address}" Foreground="#FF1F1F1F" Style="{StaticResource PhoneTextNormalStyle}" HorizontalAlignment="Left" FontSize="20" MaxHeight="30" TextTrimming="WordEllipsis" Margin="5,0,0,5"/>
<StackPanel x:Name="addressPanel" Grid.Row="2" Orientation="Horizontal" Margin="5,0,0,5">
<Image x:Name="phone" Stretch="Uniform" Margin="0,0,5,0" Height="25" Source="Images/list_phone.png" />
<TextBlock x:Name="phoneTextBlock" Text="{Binding Phone1}" Foreground="#FF501F6E" Style="{StaticResource PhoneTextNormalStyle}" HorizontalAlignment="Left" FontSize="20" MaxHeight="30" TextTrimming="WordEllipsis"/>
</StackPanel>
<Image x:Name="line" Grid.Row="3" Width="460" HorizontalAlignment="Center" Source="Images/separator.png" />
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</Grid>
After that in code behind file, i'm binding like below.
private void CompaniesPage_Loaded(object sender, RoutedEventArgs e)
{
if (isPageAlreadyLoaded == false)
{
List<Company> companies = (List<Company>)DataContext;
companiesList.ItemsSource = companies;
isPageAlreadyLoaded = true;
}
}
While debugging I've checked the variable List companies variable in the code behind file before setting to list and i'm getting the data correctly.
But the data is not binding to the list. I don't know why data was not binding.
Now to test i've replaced the binding with static text. And I run the application then also data is not visible in the page. But on list item changed i'm getting the data. This means that my xaml page is unable to display data. So could you please tell me what was the wrong in my xaml page design which is at below.
<phone:PhoneApplicationPage
x:Class="STCDirectory.CompaniesPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneForegroundBrush}"
SupportedOrientations="Portrait" Orientation="Portrait"
mc:Ignorable="d"
shell:SystemTray.IsVisible="True" Loaded="CompaniesPage_Loaded"
xmlns:my="clr-namespace:System.Windows.Controls;assembly=WindowsPhoneWatermarkTextBoxControl">
<!--LayoutRoot is the root grid where all page content is placed-->
<Grid x:Name="LayoutRoot">
<Grid.Background>
<ImageBrush Stretch="UniformToFill" ImageSource="/STCDirectory;component/Images/search_list_bg.png" />
</Grid.Background>
<Grid.RowDefinitions>
<RowDefinition Height="80"/>
<RowDefinition Height="80"/>
<RowDefinition Height="80"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<!--TitlePanel contains the name of the application and page title-->
<StackPanel x:Name="TitlePanel" Grid.Row="0" Orientation="Vertical" Margin="0,0,0,10" >
<TextBlock x:Name="header" Text="STC Directory" HorizontalAlignment="Left" Margin="10,20,0,5" Foreground="#FF501F6E" FontWeight="Bold" FontSize="35" />
</StackPanel>
<StackPanel x:Name="buttonsBar" Grid.Row="1" Orientation="Horizontal" Margin="0,10,0,0">
<Button Content="Button" Height="70" HorizontalAlignment="Left" Margin="14,1,0,0" Name="button1" VerticalAlignment="Top" Width="160" />
<Button Content="Button" Height="70" HorizontalAlignment="Left" Margin="130,1,0,0" Name="button2" VerticalAlignment="Top" Width="160" />
</StackPanel>
<StackPanel x:Name="searchBar" Grid.Row="2" Orientation="Horizontal" >
<my:WatermarkTextBox Name="textBlock1" Width="400" Margin="-5,0,-10,0" WatermarkText="{Binding Path=LocalizedResources.SearchHint, Source={StaticResource LocalizedStrings}}" TextWrapping="Wrap" Foreground="Black" TextAlignment="Left" BorderBrush="{x:Null}" FontSize="25">
<my:WatermarkTextBox.Background>
<ImageBrush ImageSource="/STCDirectory;component/Images/search_box.png" />
</my:WatermarkTextBox.Background>
</my:WatermarkTextBox>
<Button x:Name="serchButton" Style ="{StaticResource ButtonStyleIB}" VerticalAlignment="Center" Height="70" Click="serach_button_clicked">
<Image Source="/STCDirectory;component/Images/search.png" Stretch="Fill" />
</Button>
</StackPanel>
<Grid x:Name="ContentPanel" Grid.Row="3" Background="White" Margin="0,-3,0,0">
<ListBox x:Name="companiesList"
SelectionChanged="companiesList_SelectionChanged">
<ListBox.ItemTemplate>
<DataTemplate>
<Grid x:Name="listItem">
<Grid.RowDefinitions>
<RowDefinition Height="40"/>
<RowDefinition Height="30"/>
<RowDefinition Height="30"/>
<RowDefinition Height="10"/>
</Grid.RowDefinitions>
<TextBlock x:Name="nameTextBlock" Grid.Row="0" Text="Kentuc Fried Chicken(KFC)" Foreground="#FF501F6E" Style="{StaticResource PhoneTextNormalStyle}" HorizontalAlignment="Left" FontSize="28" MaxHeight="40" TextTrimming="WordEllipsis" Margin="5,0,0,5"/>
<TextBlock x:Name="addressTextBlock" Grid.Row="1" Text="Al riyadh" Foreground="#FF1F1F1F" Style="{StaticResource PhoneTextNormalStyle}" HorizontalAlignment="Left" FontSize="20" MaxHeight="30" TextTrimming="WordEllipsis" Margin="5,0,0,5"/>
<StackPanel x:Name="addressPanel" Grid.Row="2" Orientation="Horizontal" Margin="5,0,0,5">
<Image x:Name="phone" Stretch="Uniform" Margin="0,0,5,0" Height="25" Source="Images/list_phone.png" />
<TextBlock x:Name="phoneTextBlock" Text="966123456" Foreground="#FF501F6E" Style="{StaticResource PhoneTextNormalStyle}" HorizontalAlignment="Left" FontSize="20" MaxHeight="30" TextTrimming="WordEllipsis"/>
</StackPanel>
<Image x:Name="line" Grid.Row="3" Width="460" HorizontalAlignment="Center" Source="Images/separator.png" />
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</Grid>
</Grid>
I'm looking forward for your response
Thanks,
Basina
public MainPage()
{
this.InitializeComponent();
List<Company> companies = new List<Company>();
Company comp = new Company();
comp.CompanyName = "hellocpmp1";
companies.Add(comp);
companies.Add(comp);
companies.Add(comp);
companies.Add(comp);
companies.Add(comp);
companies.Add(comp);
companies.Add(comp);
companies.Add(comp);
companies.Add(comp);
companies.Add(comp);
companies.Add(comp);
companiesList.ItemsSource = companies;
}
i have tried it like above and it is working fine so in your case thr may be problem with no data coming from web service.
<phone:PhoneApplicationPage
x:Class="PhoneApp1.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:toolkit="clr-namespace:Coding4Fun.Toolkit.Controls;assembly=Coding4Fun.Toolkit.Controls"
mc:Ignorable="d"
shell:SystemTray.IsVisible="True">
<!--LayoutRoot is the root grid where all page content is placed-->
<Grid x:Name="ContentPanel" Background="Transparent" >
<ListBox x:Name="companiesList" ItemsSource="{Binding companies}"
SelectionChanged="companiesList_SelectionChanged_2">
<ListBox.ItemTemplate>
<DataTemplate>
<Grid x:Name="listItem">
<Grid.RowDefinitions>
<RowDefinition Height="40"/>
<RowDefinition Height="30"/>
<RowDefinition Height="30"/>
<RowDefinition Height="10"/>
</Grid.RowDefinitions>
<TextBlock x:Name="nameTextBlock" Grid.Row="0" Text="{Binding CompanyName}" Foreground="#FF501F6E" />
<TextBlock x:Name="addressTextBlock" Grid.Row="1" Text="Al riyadh" Foreground="#FF1F1F1F" />
<StackPanel x:Name="addressPanel" Grid.Row="2" Orientation="Horizontal" Margin="5,0,0,5">
<Image x:Name="phone" Stretch="Uniform" Margin="0,0,5,0" Height="25" Source="Images/list_phone.png" />
<TextBlock x:Name="phoneTextBlock" Text="966123456" Foreground="#FF501F6E" />
</StackPanel>
<Image x:Name="line" Grid.Row="3" Width="460" HorizontalAlignment="Center" Source="Images/separator.png" />
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</Grid>
i have found your problem thr is something wrong with your style part of your textblocks so i have removed it . i have put some working code with binding as well as hardcoded text . tell me if your problem got solved.