I'm working on UWP App with c#.
And i can't binding image from document Library in sharepoint,
I can Retrieve data from list or info of document library by using CSOM, but how to display image?
When i open image's link on browser i have to give username and password before.
So i think that's problem in authentification?
I'm trying to get file and after display it like this,but i don't know how to bind image:
using (var context=new ClientContext("https://xxxx.sharepoint.com/sites/demo/"))
{
context.Credentials = new SharePointOnlineCredentials("xxx#xxxx","Pass");
var file =context.Web.GetFileByServerRelativeUrl("/sites/Demo/mylib/1.jpg");
context.Load(file);
await context.ExecuteQueryAsync();
Microsoft.SharePoint.Client.File File doc = file;
list.add(new Person(1,"Name","Description", ??Image?? ));
}
**XAML CODE**
<DataTemplate x:Key="ControlCategoryPrincipal" x:DataType="data:Person">
<Ellipse Margin="8,0" HorizontalAlignment="Left" Height="80" Width="80">
<Ellipse.Fill>
<ImageBrush Stretch="UniformToFill">
<ImageBrush.ImageSource>
<BitmapImage UriSource="{x:Bind Image}" />
</ImageBrush.ImageSource>
</ImageBrush>
</Ellipse.Fill>
</Ellipse>
</DataTemplate>
...
<GridView x:Name="gridPrinc"
AutomationProperties.AutomationId="GroupGridView"
ItemTemplate ="{StaticResource ControlCategoryPrincipal}"
ItemsSource="{x:Bind list,Mode=OneWay}"
ScrollViewer.VerticalScrollMode="Disabled"
SelectionMode="None" Loaded="gridPrinc_Loaded">
</GridView>
**MODEL**
public class Person
{
private int id;
private String name;
private String image;
private String description;
... + GETTERS + SETTERS
public Person(int id, String n, String desc, String img)
{
this.Id = idd;
this.Name = n;
this.Image = img;
this.Description = desc;
}
}
list property on the PropertyChanged event did not occur if the output should not
list ObservableCollection property Taxes output because this event does not occur unless CollectionChanged
x: Bind the OneTime mode is because when data for later binding can be integral
Related
Faced the need to select a fragment of text in TextBlock, namely certain keywords on which the ListBox was filtered, this text block itself and containing
XAML variant, title property is not bound
<ListBox Name="ProcedureList" ItemsSource="{Binding Path=ProceduresView.View}">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Name="ProcedurePanel" PreviewMouseDown="ProcedurePanel_OnPreviewMouseDown">
<DockPanel Width="{c:Binding ElementName=MainPanel, Path=Width-40}">
<!--<TextBlock Name="MainText" TextWrapping="Wrap" FontSize="16" Text="{Binding Path=title}" HorizontalAlignment="Left" />-->
<htb:HighlightTextBlock Name="MainText" TextWrapping="Wrap" FontSize="16" Text="{Binding Path=title}" HorizontalAlignment="Left">
<htb:HighlightTextBlock.HighlightRules>
<htb:HighlightRule
IgnoreCase="{Binding IgnoreCase, Source={StaticResource SourceVm}}"
HightlightedText="{Binding Path=title, Converter={StaticResource getFilter}}">
<htb:HighlightRule.Highlights>
<htb:HighlightBackgroung Brush="Yellow"/>
</htb:HighlightRule.Highlights>
</htb:HighlightRule>
</htb:HighlightTextBlock.HighlightRules>
</htb:HighlightTextBlock>
</DockPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
A component written by our compatriot with open source is used
Component
Description of component
The commented code is an old TexBlock with no selection
The new HighlightTextBlock component perfectly selects the text if you use a static resource, as in the example, but when I try to bind it to the current text it can not find this field :(, I'm new in WPF help figure it out
HightlightedText="{Binding Path=title, Converter={StaticResource getFilter}}"
How correctly to anchor this property to title?
DataContext structure
public ObservableCollection<Procedure> Procedures { set; get; }
public CollectionViewSource ProceduresView { set; get; } = new CollectionViewSource();
....
Procedures = new ObservableCollection<Procedure>();
ProceduresView.Filter += Procedures_Filter;
ProceduresView.Source = Procedures;
....
public class Procedure : ObservableObject
{
....
public String title { get; set; }
....
}
....
// Simple filtering
void Procedures_Filter(object sender, FilterEventArgs e)
{
Procedure procedure = (Procedure) e.Item;
Boolean flag = false;
if (!string.IsNullOrEmpty(filter))
{
Setting.Filter sfilter = new Setting.Filter();
sfilter.type = "искать везде";
sfilter.text = filter;
ObservableCollection<Setting.Filter> arr = new ObservableCollection<Setting.Filter>();
arr.Add(sfilter);
if (Utils.AssignedProcedureFromFilter(procedure, arr)) flag = true;
}
else flag = true;
e.Accepted = flag;
}
Video with problem description
Simplified project emitting my functional
On the Russian-speaking forum they explained to me that:
Your case, in fact, is more serious. DataContext you, apparently, the
right one. But your Binding expression is inside the HighlightRules
property setter, which is not part of the visual tree (because it is
not available as a Child element of your control). And elements that
are not inside the visual tree, participate in bindings are only
limited: they do not inherit DataContext, nor access by name through
ElementName. As a solution, bind to an element via x: Reference. In my
(heavily cut) test case, HightlightedText = "{Binding Path =
DataContext.title, Source = {x: Reference MainText}} is triggered."
But, if directly replaced by this, a strange error works: 'Can not
call MarkupExtension. ProvideValue because of a cyclic dependency. The
properties inside the MarkupExtension can not reference objects that
reference the MarkupExtension result.
The workaround for the error was found here: you need to put your element in resources. We get this:
XAML, modified according to the recommendations
<ListBox Name="ProcedureList" ItemsSource="{Binding Path=ProceduresView.View}">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Name="ProcedurePanel" PreviewMouseDown="ProcedurePanel_OnPreviewMouseDown">
<DockPanel Width="{c:Binding ElementName=MainPanel, Path=Width-40}">
<!--<TextBlock Name="MainText" TextWrapping="Wrap" FontSize="16" Text="{Binding Path=title}" HorizontalAlignment="Left" />-->
<htb:HighlightTextBlock Name="MainText" TextWrapping="Wrap" FontSize="16"
Text="{Binding Path=title}" HorizontalAlignment="Left">
<htb:HighlightTextBlock.Resources>
<htb:HighlightRule x:Key="HR"
IgnoreCase="{Binding IgnoreCase, Source={StaticResource SourceVm}}"
HightlightedText="{Binding Path=DataContext.title, Source={x:Reference MainText}, Converter={StaticResource getFilter}}">
<htb:HighlightRule.Highlights>
<htb:HighlightBackgroung Brush="Yellow"/>
</htb:HighlightRule.Highlights>
</htb:HighlightRule>
</htb:HighlightTextBlock.Resources>
<htb:HighlightTextBlock.HighlightRules>
<htb:HighlightRulesCollection>
<StaticResource ResourceKey="HR"/>
</htb:HighlightRulesCollection>
</htb:HighlightTextBlock.HighlightRules>
</htb:HighlightTextBlock>
</DockPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
I was given advice on the restructuring of XAML, through resources, this partially solved the problem (I successfully got the title text in the converter), but the element ceased to perform its functions (allocation) During the discussion, it was suggested that the component itself should be finalized
#iRumba: In theory, the whole trick should not be necessary if you put
the HighlighRule collection (also) in a visual tree. Then the
DataContext will be automatically inherited and on idea the binding
through ElementName too will work.
#iRumba: I do not remember exactly. It seems, it is necessary to
specify to add all HighlightRule as LogicalChildren (for this purpose
on idea it is necessary to redefine protected internal override
IEnumerator LogicalChildren). This is a complicated, advanced
technique, yes.
Sorry for Google Translator
Found a solution
public class SearchHightlightTextBlock : TextBlock
{
public SearchHightlightTextBlock() : base() { }
public String SearchText
{
get { return (String)GetValue(SearchTextProperty); }
set { SetValue(SearchTextProperty, value); }
}
private static void OnDataChanged(DependencyObject source,
DependencyPropertyChangedEventArgs e)
{
TextBlock tb = (TextBlock)source;
if (tb.Text.Length == 0)
return;
string textUpper = tb.Text.ToUpper();
String toFind = ((String)e.NewValue).ToUpper();
int firstIndex = textUpper.IndexOf(toFind);
String firstStr = "";
String foundStr = "";
if (firstIndex != -1)
{
firstStr = tb.Text.Substring(0, firstIndex);
foundStr = tb.Text.Substring(firstIndex, toFind.Length);
}
String endStr = tb.Text.Substring(firstIndex + toFind.Length,
tb.Text.Length - (firstIndex + toFind.Length));
tb.Inlines.Clear();
tb.FontSize = 16;
var run = new Run();
run.Text = firstStr;
tb.Inlines.Add(run);
run = new Run();
run.Background = Brushes.Yellow;
run.Text = foundStr;
tb.Inlines.Add(run);
run = new Run();
run.Text = endStr;
tb.Inlines.Add(run);
}
public static readonly DependencyProperty SearchTextProperty =
DependencyProperty.Register("SearchText",
typeof(String),
typeof(SearchHightlightTextBlock),
new FrameworkPropertyMetadata(null, OnDataChanged));
}
Use
<parser:SearchHightlightTextBlock SearchText="{Binding Path=title, Converter={StaticResource getFilter}}" Text="{Binding title}"/>
I have a problem displaying an image in WPF. The problem is that I add the image into the Grid and I can not actually see the image. I can see the place where the image is, but not the image itself (check the image below):
Here is my code:
View:
<DataGridTemplateColumn Header="Image" Width="SizeToCells" IsReadOnly="True" Visibility="Visible">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Image Height="25" Width="50" Source="{Binding Path=ImageArticle}" />
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
Here I take the path and add it:
ContinueArticle ca = new ContinueArticle();
string ImagePath = Environment.CurrentDirectory + #"C:\iClipIT\Thumbs\" + ClipID;
ca.ImageArticle = ImagePath;
atlist.Add(ca);
And here I create the object and the getters and setters:
public static readonly DependencyProperty ArticleImageProperty
= DependencyProperty.Register("ArticleImage", typeof(string), typeof(ContinueArticle));
public string ImageArticle
{
get
{
return (string)GetValue(ArticleImageProperty);
}
set
{
SetValue(ArticleImageProperty, value);
}
}
Any clue what I'm doing wrong? I read a lot about this and I can't find the problem.
I am reading from xml file and displaying a selected item in a ListBox that is binding elements in a TextBlock. But now I want to extract a string that is displayed so that it can be converted to speech. I have a text-to-speech button that must read the contents displayed by the ListBox, but it ends up reading/ playing this:
System.Linq.Enumerable+whereSelectEnumerableIterator2[System.XML.Linq.XElement,Sleepy_Time_Stories.StroryPage+InspirationMsg]
Here's my code that reads and displays in xaml binded ListBox:
XDocument LoadData = XDocument.Load("Stories.xml"); //xml file name
var SearchData = from c in LoadData.Descendants("Messg")//xml tags
where c.Attribute("Story").Value == (string)e.Parameter
select new InspirationalMsg()
{
InspMessage = c.Attribute("InspMessage").Value,
};
displayMsg.ItemsSource = SearchData; // displaying in ListBox
txResult.Text = SearchData.ToString();
displayMsg.Visibility = Visibility.Visible;
}
public class InspirationalMsg
{
string story;
string msg;
int id;
public string Story
{
get { return story; }
set { story = value; }
}
public string InspMessage
{
get { return msg; }
set { msg = value; }
}
public int Id
{
get { return id; }
set { id = value; }
}
}
This is the xaml code for the list box:
<ListBox x:Name="displayMsg" FontFamily="Arial" FontWeight="Medium" FontSize="24" VerticalAlignment="Center" Width="400" >
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Margin="12,17,0,28" >
<TextBlock Text="{Binding InspMessage}" TextWrapping="Wrap" Foreground="White" VerticalAlignment="Center" x:Name="txStory" />
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
<ListBox.Background>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="Transparent" Offset="0" />
<GradientStop Color="#003366" Offset="1" />
</LinearGradientBrush>
</ListBox.Background>
</ListBox>
<Button x:Name="btnPlay" Content="Play for Me" HorizontalAlignment="Left" Margin="22,546,0,0" VerticalAlignment="Top" Width="157" Tapped="btnPlay_Tapped" Click="btnPlay_Click"/>
<Button x:Name="btnStop" Content="Stop" HorizontalAlignment="Left" Margin="184,546,0,0" VerticalAlignment="Top" Width="174" Tapped="btnStop_Tapped"/>
This is the XML File:
<Messg
Story="Stay blessed"
InspMessage="Your help does not come from what you have or don’t have nor what you know or don’t know. Your help comes from the Lord, the Lord which made Heaven and earth (scripture verse: Psalm 121:2)."
Id="1" />
Thanks
You should create a custom class which defines your what you want to display on Listbox. In that class, add override function ToString() which convert data into string format. Then you can dedicate list of your class to ItemSource of Listbox
You can find details on below link Binding a control to a collection of objects
Hope it to help on your issue.
Peter
I am making a WP8 application with a lot of local content in my Assets folder. So I am using a JSON file stored in the a JSON folder.
I have been able to parse the JSON to C# very easily and now I am trying to display the data in a list. I had no problem with displaying the title but I am unable to display an image, even with the filename I am got.
My images are stored in "Assets/Content/mediaXXX.jpg";
ListViewModel :
public class ListViewModel
{
public string Title { get; set; }
public string Subtitle { get; set; }
public BitmapImage ListImage { get; set; }
}
XAML
<ListBox Margin="0,1,0,0"
Height="730"
x:Name="MainList">
<ListBox.ItemTemplate>
<DataTemplate>
<Grid Height="120"
Width="480">
<StackPanel Orientation="Horizontal">
<Image HorizontalAlignment="Left"
Source="{Binding ListImage}"
Margin="12"
Stretch="UniformToFill"
Width="130"/>
<Grid>
<TextBlock x:Name="ListItemTitle"
Text="{Binding Title}"/>
<TextBlock x:Name="ListItemSubTitle"
Text="{Binding Subtitle}"/>
</Grid>
</StackPanel>
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
And my C# page
BitmapImage image = new BitmapImage(new Uri(#"Assets/Content/" + photo.filename + ".jpg", UriKind.Relative);
l.ListImage = image;
Any idea?
Code should work. Only problems that might occur is your ListBox databinding is incorrectly defined.
I don't see any .ItemsSource = or ItemsSource={Binding some_collection}
Another thing is make sure that photo.filename is returning the correct file.
Set a string debug_string = "Assets/Content/" + photo.filename + ".jpg";
Make sure everything is correct.
Last thing is to make sure the files are actually in the Assets Folder inside the project and its
BuildAction is set to Content
like so
Class File:
public class User
{
public string user { get; set; }
}
XML for the TextBlock:
<DataTemplate x:Key="DataTemplate1">
<StackPanel x:Name="Stak" Orientation="Vertical" Width="0">
<TextBlock HorizontalAlignment="Left" TextWrapping="Wrap" Text="{Binding}" Width="443" Margin="0,0,-443,0" FontSize="22"/>
<TextBlock x:Name="UserText" HorizontalAlignment="Left" Text="{Binding User}" TextWrapping="NoWrap" Width="443" Margin="0,0,-443,0" FontFamily="Segoe WP SemiLight" FontSize="23"/>
</StackPanel>
</DataTemplate>
C# code to load text:
IsolatedStorageFileStream readName = store.OpenFile("/User Information/UserName.txt", FileMode.Open, FileAccess.Read);
using (StreamReader contactName = new StreamReader(readName))
{
var name = contactName.ReadLine();
var Load = new User();
Load.user = name;
}
So Basically what this is supposed to do is when the app loads, it reads a file from the User Information folder and is meant to add it to the TextBlock text. Because I cant access the TextBlock since it's inside a Pivot Datatemplate, I've binded it.
Once the App is done reading the file it's meant to add whatever is inside the name into the textblock but it doesn't do it.